do while issue

Hi I'm working on a class project and am having a little bit of an issue with a do while loop...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34

int _tmain(int argc, _TCHAR* argv[])
{
	string optionSelected;
	
	titlePage();
	
	do
	{
		menuPage();
		cin >> optionSelected;

		switch(optionSelected.at(0))
		{
		case 's':
		case 'S':
			searchPage();
			break;
		case 'q':
		case 'Q':
			break;
		default :
			cout << "Invalid Entry" << endl;
			cin.get();
			system("cls");
			break;
		}
	}
	while((optionSelected.at(0) != 'q') || (optionSelected.at(0) != 'Q'));	
	exitPage();
	cin.get();
	return 0;
}


When I enter "q" or "Q", I would think that would make the while portion of the do/while loop false which would allow the program to proceed to exitPage(), however the loop just continues. What am I doing wrong?
while((optionSelected.at(0) != 'q') || (optionSelected.at(0) != 'Q'));

See your problem?
(hint: if you enter 'q', then of course optionSelected.at(0) != 'Q')
(optionSelected.at(0) != 'q') || (optionSelected.at(0) != 'Q')

Let's imagine that optionSelected.at(0) is 'Z'. Z is not q, so the left side is true. Z is not Q, so the right side is true. So the whole thing comes out as true.

Let's imagine that optionSelected.at(0) is 'q'. q is q, so the left side is false. q is not Q, so the right side is true. So the whole thing comes out as true.

Let's imagine that optionSelected.at(0) is 'Q'. Q is not q, so the left side is true. Q is Q, so the right side is false. So the whole thing comes out as true.

Can you think of ANYTHING that optionSelected.at(0) could be such that
(optionSelected.at(0) != 'q') || (optionSelected.at(0) != 'Q')
does NOT come out as true? No, you cannot.

Did you perhaps mean
(optionSelected.at(0) != 'q') && (optionSelected.at(0) != 'Q')?
Saying it aloud might help.

"I want the loop to keep going while the letter chosen is not q AND the letter chosen is not Q".
Got it, thanks for the help :)
Topic archived. No new replies allowed.