Problem with OR operator

My program is essentially complete except for one last section. when I use an OR operator in my condition for a do while loop it will loop even though I entered 2 for verify in the following code. If I remove the OR operator and only leave the verify != 2 condition it works. No more looping! I add the OR operator and the verify != 1 again and it loops
I'm at a loss of what to do.
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
 do
 {
    cout << "You have selected the seat in row " << y << " column " << x << endl
	<< "Price: $" << setprecision(2) << prices[y] << endl
        << "Is this information correct?" << endl
	<< "[1] Yes" << endl
	<< "[2] No" << endl
	<< "Please confirm your purchase: ";
     cin >> verify;
     if (verify == 1)
     {
	cout << "Seat in row " << y << " column " << x << " ticket purchased.";
	*totalRevenue += prices[y];
     }
     else if (verify == 2)
	cout << "Please select your seat again" << endl << endl;
     else
        cout << "Invalid Selection" << endl << endl;
 } while (verify != 1 || verify != 2);

while (verify != 1 || verify != 2);
Look at it this way - if verify is 2, "2 !=1" is satisfied. In other words, even if you type in 2, it loops again!
The Same with 1. Let verify be 1. This time, the condition verify!=2 is satisfied! So it endlessly loops.
Make it
while (verify != 1 && verify != 2);
That is, repeat the loop if verify is not 1 AND verify is not 2
Oh! that's right
Haha now I feel dumb for not considering that. I was looking at the operator as an AND instead of OR operation-wise
Last edited on
Topic archived. No new replies allowed.