0

我看过类似的问题,但作为一个完全的新手,他们没有多大帮助,当我尝试运行我的最终 if 语句时,我遇到了这个错误,我怎样才能让我的 cout 语句更清晰?它的预期目的是输出它可以接受多少袋垃圾,用户试图给它多少,如果不能把它们都拿走,会剩下多少袋。

while(( reg < 50) && (met< 20) && (glass < 20))
{
reg=reg+reg; met=met+met; glass=glass+glass;
cout<< " I have enough "<< endl;


if(reg+=reg > 50){
cout<< "I can only accept " << 50 - (reg+=reg) << "of your " << (reg+=reg)<<" regular     bags of garbage, I'll leave the other " << 50 - (reg+= reg)<< " I'll leave the other " << reg- (50 - reg+=reg)<< endl;
}
4

1 回答 1

1
50 - reg += reg;

operator+=的优先级低于operator-。上述语句解释为:

(50 - reg) += reg;

这是行不通的。你可能想要:

50 - (reg += reg);
于 2012-10-02T00:10:23.520 回答