View Full Version : Loop help
imported_ExOdUs
07-13-2003, 01:51 AM
ive been trying to have my program loop over again with the while loop and the do-while loop and its not working.I have my program ask if they want the program to start over again press yes or no and everything i know i tryed and the program wont loop can some one help me.OH and im written the program in dos not windows app
DNAunion2000
07-13-2003, 02:04 PM
ExOdUs: ive been trying to have my program loop over again with the while loop and the do-while loop and its not working.I have my program ask if they want the program to start over again press yes or no and everything i know i tryed and the program wont loop can some one help me.OH and im written the program in dos not windows app
DNAunion2000: It would help if you provided your code so that we might see where the problem lies and give you an exact remedy.
When posting code, to retain the tabs (such as indentation) and other whitespace wrap your code in and [/code...] tags (leaving out the "..." I added to prevent the site from interpretting them as start and end tags).
Here's what I think might work (it's a fragment, not a whole program, and its written off the top of my head)
[code]
do
{
cout << "Make a selection: " << endl;
cout << "'A' = <whatever>" << endl;
cout << "'B' = <something else>" << endl;
cout << "'Q' = Quit" << endl;
cin >> userChoice;
switch (userChoice)
{
case 'A':
case 'a':
// do whatever
break;
case 'B':
case 'b':
// do something else
break:
case 'Q':
case 'q':
break:
default:
cout << "Invalid selection made...please try again." << endl;
}
} while (userChoice != 'Q' && userChoise != 'q');
DNAunion: The case that handles 'Q' does nothing, but when the while test at the end of the loop is performed, the flow of execution breaks out of the loop.
split
08-05-2003, 05:01 PM
A switch...while loop?
split
08-05-2003, 05:02 PM
Oh no, I misread it. Sorry.
vBulletin® v3.7.0, Copyright ©2000-2009, Jelsoft Enterprises Ltd.