if statement not working right?

The || doesn’t quite mean what you think it means. The correct approach is:

if (yesno != 'Y' && yesno != 'N') { ...

This evaluates each side of the && independently, and the result is true if both sides are true.

Note that

if (yesno != 'Y' || yesno != 'N') { ...

will always be true because any given character is either not Y or it is not N. This is probably not what you want.

Leave a Comment