I am trying to form an if statement like so:
int myVariable = -1;
if (0 <= myVariable <= 99)
{
// Do something
}
However, if I assigned -1 to myVariable, which is an int, the if-statement still evaluations to true.
What am I doing wrong ?
That is not the correct way to say what you want in C++ syntax. You want:
What you wrote does the following:
1) Evaluate
0 <= myVariable, which in your example will be false (converted to 0 in C++ in this context)2) Then this result (0) is compared against <= 99, so C++ reads “0 <= 99”, which is true, so the if statement is true.