The problem is that you are taking sloppy English and translating it literally to create broken C++.
When you say:
the character is not 'N' or 'n'
this, while commonplace, is wrong. For the same reason, your C++ code is wrong. You are comparing getche()
to 'N' || 'n'
, an expression which applies boolean-OR to two char
s, always resulting in true
.
You mean to say either of:
the character is neither 'N' nor 'n'
the character is not 'N' and the character is not 'n'
C++ only has an equivalent for the latter construct, and here it is:
if (getche() != 'N' && getche() != 'n')
Of course, you only want to read one character, so:
const char c = getche();
if (c != 'N' && c != 'n')
3
solved Why does the testing condition has no effect