Using multiple Or operators in a while loop

I was wanting to create a loop for data entry verification so that it loops only when a user enters a wrong number. In my code below, you can see that the while loop will only break with the numbers 1, 5, and 10. The code works correctly if I limit my condition to one number but will not work with more than one. Can anyone tell me why this is happening? I have not been able to find anything in the book I have been reading (An Intro to C++ by Diane Zak 6th ed.) or anywhere else on the web.

#include <iostream>
using namespace std;

int main ()
{
int number = 0;

cout << "Choose one of the following numbers: 1, 5, or 10: ";
cin >> number;

while (number != 1 || number != 5 || number != 10)
{
cout << "\nError: Choose ONLY one of the following numbers:1, 5, or 10: ";
cin >> number;
}

cout << "\nYou have chosen: " << number << endl;

system("pause");
return 0;
}
If number == 1, then:

condition A: number != 1 is false;
condition B: number != 5 is true;
condition C: number != 10 is true.

false or true or true is true
It looks like I needed to input && operators instead of || operators. The logic for the while loop as seen above creates an infinite loop. The while loop will always evaluate to true even though one of the conditions will evaluate to false. This is fixed by using && operators so that if one condition evaluates to false, the while loop evaluates to false and discontinues the loop.

while (number != 1 && number != 5 && number != 10)

Thank you.
Topic archived. No new replies allowed.