#include <iostream>
#include <limits>
usingnamespace std;
int main(int argc, char *arv[])
{
cout << "enter 1 or 2: ";
int response;
cin >> response;
if ((response != 1) || (response !=2))
cout << "you must enter 1 or 2";
cin.sync();
cout << endl;
cout << "Press ENTER to continue...";
cin.ignore(numeric_limits<streamsize>::max(), '\n' );
}
by reading it i would think the if statement would fire if the response was not equal to one or not equal to 2. yet the if statement fires when i respond with 1. why is that.
i will have to look at it over because it still doesnt make sense to me. if it says true condition if not 1 or not 2 then why would it also be true if i type 1.
Consider it this way. Let's say you input 1:
- Is 1 not equal to 1? No
- Is 1 not equal to 2? Yes
- Is one OR the other true? Yes, we run the if statement.
Let's say you input 2:
- Is 2 not equal to 1? Yes
- Is 2 not equal to 2? No
- Is one OR the other true? Yes, we run the if statement.
Any other number:
- Is X not equal to 1? Yes
- Is X not equal to 2? Yes
- Is one OR the other true? Yes, we run the if statement.