pow() error

I am having trouble with this bit of code:

if((a < b < c) && (a % 1) == 0 && (b % 1) == 0 && (c % 1) == 0 && pow(c, 2) = pow(a, 2) + pow(b, 2))

With this error:
Question9.cpp:29:101: error: lvalue required as left operand of assignment


Now, character 101 is on the brace after pow(b, 2)

What is the issue here?
The = after the brace. Also, a<b<c certainly doesn't do what you seem to expect and what else can a%1 possibly be other than 0?
I'll just try to even it out as much as possible. Thanks!
Basically your problem is that left of the assignment symbol (=) there is not an expression that has an address to be assigned to.
You cannot assign a value to
(a < b < c) && (a % 1) == 0 && (b % 1) == 0 && (c % 1) == 0 && pow(c, 2) so the compiler complains. Otherwise it would not.

Also a<b<c compiles fine (not as you expect though as @Ben Duncan mentioned.

(a % 1) == 0 is equal to (a % 1)

Check your expression for errors. As a troubleshoot approach I would recommend to brake this long condition to more than one.
Last edited on
I am doubtfull about
(a < b < c)
and dont understand why are you putting the expression
pow(c, 2) = pow(a, 2) + pow(b, 2)

in the if condition .
I would totally say that this:
pow(c, 2) = pow(a, 2) + pow(b, 2)
is your problem. I assume that you want:
pow(c, 2) == pow(a, 2) + pow(b, 2)

In total, I would do:
1
2
3
4
5
if((a < b) && (b < c) &&
  ((a % 1) == 0) && //This is always true so I would just delete this line
  ((b % 1) == 0) && //This is always true so I would just delete this line
  ((c % 1) == 0) && //This is always true so I would just delete this line
  (pow(c, 2) == pow(a, 2) + pow(b, 2))) //I added an extra set of brackets and fixed the == 


Note, for long if statements like this, it can be a good idea to break it into multiple lines. This will make it a little easier to read, you can add comments for each condition and will often allow you to comment out and add conditions very easily for debugging.
Last edited on
Yeah, I got it to work, but, as you could all see, it was really bad code before.

As Stewbond mentions, it would have always been an int, so checking was irrelevant.

I think I got it to work like this:

1
2
3
4
5
if(pow(c, 2) == pow(a, 2) + pow(b, 2)){
     if(a < b && b < c){
          /*Do something*/
     }
}


Stewbond and I pretty much got the same thing here. Though, I had help from Stack Overflow.

Thanks for all your help!
Last edited on
Topic archived. No new replies allowed.