Do-while loop repeating menu help

I need to write a program that repeats a menu unless the user decides to quit. I think my setup could have been wrong?

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
35
36
37
38
39
  int main ()
{
	string xstring; 
	int choice;
	int Q;
	


	cout << "Enter a string: ";
	cin >> xstring;
	
	do
	{
		cout << "USE THIS MENU TO MANIPULATE YOUR STRING\n";
		cout << "----------------------------------------\n";
		cout << "1) Inverse the string\n";
		cout <<	"2) Reverse the string\n";
		cout <<	"3) To Uppercase\n";
		cout <<	"4) Jumble String\n";
		cout <<	"5) Count Number of Words\n";
		cout <<	"6) Count Constants\n";
		cout <<	"7) Enter a Different String\n";
		cout <<	"8) Print The String\n";
		cout <<	"Q) Quit\n";

		cin >> choice;
	}
	
	while (choice != 'Q');
	
	




	system("PAUSE");
	return 0;

}
Your problem is choice is an int and you want to assign a char to it in order to exit the loop.
Last edited on
As Annatar pointed out, choice is an integer instead of a character, so on line 26 if you input a character, the input operation will fail, leaving choice uninitialized when you compare to it on line 29. There is an extremely small chance that it happens to compare equal since it is left uninitialized.
omg i feel pretty dumb lol. Just one more quick question, when i use a switch statement for the string manipulation options, i would put that inside the do-while loop or would i put it on the outside of the do-while loop?(The string needs to be continuously manipulated, depending on what input the user uses)
Last edited on
You want the switch to be inside the loop. Do note that you can't switch on strings, you will need to use if statements instead.
Last edited on
awesome! you guys are the best thank you so much :)
Topic archived. No new replies allowed.