New to the community and programming. I was curious as to why these two logical statements are equivalent in my program. I can't seem to wrap my head around this specific logic at the moment, and I wanted to understand why it works this way.
Initially, I had written the following:
char c;
do {
cin >> c;
cout << "You entered: " << c << "\n";
} while (c != 'Y' || c != 'y' || c != 'N' || c || 'n');
return 0;
}
However, this does not seem to work unless I use &&. Later, I found out that using or does work, but my negation must be on the outside. These are the two conditionals that confuse me. Why are they logically equivalent?
while (!(c == 'Y' || c == 'y' || c == 'N' || c || 'n')); // Will run until c is the following
while (c !='Y' && c != 'y' && c != 'N' && c != 'n'); // Will also run but without being negated.