-3

I got this error in my code while compiling here is the code

#include <iostream>
using namespace std;
int main()
{
    int l,n,w,h;
    cin>>l>>n;
    while(n--){
        cin>>w>>h;
        if(w>l||h>l)
            cout<<"CROP IT"<<endl;
        if(w==l&&h==l&&w=h)
            cout<<"ACCEPTED"<<endl;
        if(w<l||h<l)
            cout<<"UPLOAD ANOTHER"<<endl;
    }
}

and the error

11:22: error: lvalue required as left operand of assignment

STF
  • 1,485
  • 3
  • 19
  • 36
Koushal Deva
  • 119
  • 2
  • 4
  • This is a repeated question. Please refer to: http://stackoverflow.com/questions/19973320/error-lvalue-required-as-left-operand-of-assignment-c – Sampath Jul 05 '16 at 05:51
  • 4
    Using the spacebar would make the cause much easier to spot. – molbdnilo Jul 05 '16 at 05:57

2 Answers2

0

Your if(w==l&&h==l&&w=h) is likely wrong. Because of operator precedence, it is doing if((w==l&&h==l&&w)=h). The w==l&&h==l&&w part creates a temporary value. Temporaries are always rvalues, and you can't assign h to it.

I suspect you meant to write if(w==l&&h==l&&w==h), but really, what's the point of the last w==h? If both w and h are equal to l, then surely w is equal to h.

evan
  • 1,463
  • 1
  • 10
  • 13
0

Because of operator precedence, (w==l && h==l && w=h) is treated as ((w==l && h==l && w) = h). The first part is an rvalue, so you cannot assign it to h.

You wanted to write for sure (w==l && h==l && w==h).

Mattia F.
  • 1,720
  • 11
  • 21