< and <= are operators. They take two arguments and returns
true or
false depending on which argument is bigger.
10 < numOfTeeth <= 200
is treated as
(10 < numOfTeeth) <= 200
――――――――――――
Lets say numOfTeeth is 5. That means
10 < numOfTeeth
will return
false.
false <= 200
is treated as
0 <= 200
so the whole expression will return
true.
――――――――――――
Now, lets say numOfTeeth is 15. That means
10 < numOfTeeth
will return
true.
true <= 200
is treated as
1 <= 200
so the whole expression will return
true.
――――――――――――
So whatever value you chose the whole expression will always return
true. To test two things you should split each test into it's own expression and combine them using the && (AND) operator, like this:
10 < numOfTeeth && numOfTeeth <= 200
The way you are using it inside your code the
10 < numOfTeeth
part is not really needed because it's already tested by the previous if statement
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16
|
if (numOfTeeth <= 10)
{
cout << "\nXenomorph classification: Green" << endl;
}
else if (/*10 < */numOfTeeth <= 200)
{
cout << "\nXenomorph classification: Yellow " << endl;
}
else if (/*200 < */numOfTeeth <= 1000)
{
cout << "\nXenomorph classification: Orange " << endl;
}
else /*if (numOfTeeth > 1000)*/
{
cout << "\nXenomorph classification: Red " << endl;
}
|