if (0 < x < 42)
Valid syntax in Python, with expected behaviour, that syntax is valid in C++, but parsed as if ((0 < x) < 42) so false/true converted to 0/1 and then tested against < 42 -> always true.
Condition must be tested with separate comparisons: if (0 < x && x < 42)