This condition:
(ch != 'n' || 'y')
Is probably not doing what you want. It is interpreted by the compiler like this:
((ch != 'n') || 'y')
Which means "if ch
is not the character n
OR if the character y
". If your machine uses ASCII, then y
has the value 121. What happens if you do:
((whatever) || 121)
For the boolean OR
operator (||
) the value 0
represents false and every other value represents true. And what do you get when at least least of the operands of a boolean OR operation are true? You get true.
So, your condition is, essentially, the same as simply writing
(1)
It looks like you want:
(ch != 'n' && ch != 'y');