需要左值作为赋值错误的左操作数通过 if 语句

lvalue required as left operand of assignment error via if statement

本文关键字:操作数 if 语句 赋值 错误      更新时间:2023-10-16

我看过类似的问题,但作为一个完全的新手,它们并没有多大帮助,当我尝试运行我的最终 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;
}
50 - reg += reg;

operator+=的优先级低于operator-。上述声明被解释为:

(50 - reg) += reg;

这行不通。您可能想要:

50 - (reg += reg);