Hey guys, i'm a college freshman taking an introductory C++ course.
I'm fairly familiar with flow control, however whenever I try to run the program below it seems that my "if" statements inside my do while loop don't appear to get checked. I'm not sure what is wrong with my code.
= is not a relational operator, it's the assignment operator. x = y the value of y into x and evaluates to the new value of x. In other words, the true branch of
The compiler will remind you if you let it (compile with warnings enabled).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
int main()
{
int level = 8 ;
if( level = 0 ) // LLVM -Wall -Wextra warning: using the result of an assignment as a condition without parentheses
// LLVM -Wall -Wextra note: place parentheses around the assignment to silence this warning
// LLVM -Wall -Wextra note: use '==' to turn this assignment into an equality comparison
// GNU -Wall -Wextra warning: suggest parentheses around assignment used as truth value
// microsoft -W4 -analyze warning: Incorrect operator: assignment of constant in Boolean context. Consider using '==' instead.
// microsoft -W4 -analyze warning: assignment within conditional expression
{
// ...
}
}