Mike Shamus
Mike Shamus

Reputation: 45

lvalue required as left operand of assignment error via if statement

I've looked at similar questions, but being a total newbie at this, they haven't helped much, when I try to run my final if statement I run into this error, how can I make my cout statement clearer? Its intended purpose is to output how many bags of garbage it can accept, how many the user is trying to give it, and how many bags will be left over if it cannot take them all.

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;
}

Upvotes: 0

Views: 505

Answers (1)

David G
David G

Reputation: 96810

50 - reg += reg;

operator+= has lower precedence than operator-. The above statement is interpreted as:

(50 - reg) += reg;

which won't work. You probably wanted:

50 - (reg += reg);

Upvotes: 1

Related Questions