To summarize it quickly, why isn't 2 < x < 9
equal to 2 < x && x < 9
?
This is the test code I've written:
#include <iostream>
int main()
{
int nums[] = { 5 , 1, 10};
// We are gonna check if the number is in the range 2 - 9
for (auto e : nums)
{
if (2 < e < 9)
std::cout << "2 < " << e << " < 9" << std::endl;
if(2 < e && e < 9)
std::cout << "2 < " << e << " and " << e << " < 9" << std::endl;
}
std::cin.get();
}
Here is the output I'm getting:
2 < 5 < 9
2 < 5 and 5 < 9
2 < 1 < 9
2 < 10 < 9
It looks like only 2 < e && e < 9
works correctly.