新手错误与"expression must have integral or enum type"
Newbie error with "expression must have integral or enum type"
温柔点…我学c++已经5周了。我挖了又挖,不明白为什么Visual Studio Express(和在线编译器)会抛出错误。
请注意,为了清晰起见,我包含了所有声明——大多数声明在代码的不同部分使用。得到错误的行是这样的:newsharePrice = perchangeEnd * profitLoss << 'n';
我得到的错误是c2296,左操作数的类型是double。我有不知道为什么它不像这样…我把其他的双数相乘就可以了。
double numberShares,
sharePrice,
profitLoss,
profitGain,
commissionPaid,
commissionCost,
sharesCost,
totalshareCost,
newtotalshareCost,
newcommissionCost,
newsharePrice;
double perChange;
double perchangeEnd;
const int minVALUE = 1;
const int maxVALUE = 100;
int seed = time(0);
srand (seed);
perChange = (rand() % (maxVALUE - minVALUE + 1)) + minVALUE;
cout << perChange << 'n';
perchangeEnd = perChange / 100;
int flip = rand() % 2 + 1;
if (flip == 1)
profitLoss = 1;
else
profitLoss = -1;
newsharePrice = perchangeEnd * profitLoss << 'n';
newsharePrice = newsharePrice + sharePrice;
cout << newsharePrice << 'n';
newtotalshareCost = numberShares * newsharePrice;
cout << "You've now paid " << newtotalshareCost << " for your shares." << 'n';
newcommissionCost = newtotalshareCost * commissionRate;
cout << "The new amount of commission for this is " << newcommissionCost << " ." << '/n';
好吧,看看有问题的那行:
newsharePrice = perchangeEnd * profitLoss << 'n';
// ▲▲▲▲▲▲▲▲
<< 'n'
不是乘法的一部分;从你的cout
线复制面食失败?
在这种情况下,编译器别无选择,只能假设您正在尝试执行位左移操作,这在double
s上无法执行;
虽然编译错误现在已修复,但您的域错误仍然存在(今天是星期五,不是吗?)为什么股价波动会以任何方式影响你的佣金?你已经有了自己的位置。您还可以使用浮点精度来衡量您的股票数量。虽然在某些情况下,您的股份数量可能不均匀,但这种情况很少发生。你是真的在解释这个还是只是错误地使用了double?大多数系统会将共享数计算为整数。此外,你可以有负的位置,这之后所有的计算将给负佣金!经纪人不会同意;)。最后,但并非最不重要的是,美国佣金很少以交易价值的百分比表示。它通常以每股几美分的形式收费(对大多数零售经纪人来说,这是固定的交易成本)。
相关文章:
- 瓦尔格林德:数学函数"Conditional jump or move depends on uninitialised value(s)"
- C++核心准则 C35 对于接口类"A base class destructor should be either public and virtual, or protected and nonv
- 使用模板进行堆栈实现; "name followed by :: must be a class or namespace"
- Android NDK clang 编译器错误在 Windows 上显示'No such file or directory'
- 模式"allocate memory or use existing data"
- N-API include an .so or dll
- 已解决 - C++ 的崇高文本中的"fatal error: opencv: no such file or directory"
- 将 OR 逻辑运算符从 C++ 转换为 Fortran
- CPP 中的瓦尔格林德和记忆泄漏:"Conditional jump or move depends on uninitialised values"
- 我如何将 OR 与 if 语句一起使用字符串
- 将 if 语句中的字符与 or 进行比较
- Google Or-Tools Glop:如何创建指向 const 对象的指针数组?
- 当初始值设定项是基类名时'initializer does not name a non-static data member or base class'错误
- 编译为 cuda 内核调用提供了"expression must have integral or unscoped enum type"
- 模板元编程:"does not have integral or enumeration type"
- 字符串初始化失败:"expression must have integral or unscoped enum type"
- 错误消息在 C++ 中显示为"expression must have integral or enum type"
- unordered_map关键问题"expression must have integral or unscoped enum type"
- 新手错误与"expression must have integral or enum type"
- C++错误:"Expression must have integral or enum type"