-
driving me nuts
Hi all,
I cant show you any code cos im at work, but hes what im tryng to do....
I have a menu (switch statement) and when the user enters the option required it branches off to a new funtion, how would i get it to return to the origanal menu?
Any ideas would be gratley received....
Cheers guys
-
Encase your switch statement in a loop that is exited when the user selects a particular option from the menu. There are plenty of examples on here... try searching and see what you come up with.
-
Code:
#include <iostream>
using std::cout;
using std::endl;
using std::cin;
void Sing(){
cout << "Lalala" << endl << endl;
}
void Shout(){
cout << "Ahhhhhh!!!" << endl << endl;
}
int main(){
char ch;
bool bLoop = true;
while(bLoop){
cout << endl << "Enter;" << endl << "1. To Sing" << endl;
cout << "2. To Shout" << endl << "3. To Quit" << endl;
cout << "Then press return" << endl;
cin >> ch;
if(cin.peek() != '\n'){
cout << "Error - 1 digit numer only!" << endl;
while(cin.peek() != '\n')cin.ignore();
continue;
}
switch(ch){
case '1':
Sing();
continue;//The continue statement sends it to the top of the loop
case '2':
Shout();
continue;
case '3':
bLoop = false;
break;
default:
cout << "Wrong selection! Try again" << endl;
continue;
}
}
cout << "That's all folks!" << endl;
return 0;
}
-