![]() |
| | #1 |
| Registered User Join Date: Oct 2002
Posts: 59
| driving me nuts 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 |
| boontune is offline | |
| | #2 |
| End Of Line Join Date: Apr 2002
Posts: 6,240
| 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.
__________________ When all else fails, read the instructions. If you're posting code, use code tags: [code] /* insert code here */ [/code] |
| Hammer is offline | |
| | #3 |
| &TH of undefined behavior Join Date: Aug 2001
Posts: 5,219
| 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;
}
__________________ "If A is success in life, then A equals x plus y plus z. Work is x; y is play; and z is keeping your mouth shut." Albert Einstein (1879 - 1955) Board Rules |
| Fordy is offline | |
| | #4 |
| Registered User Join Date: Oct 2002
Posts: 59
| cheers guys |
| boontune is offline | |
![]() |
| Thread Tools | |
| Display Modes | |
|
Similar Threads | ||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| An error is driving me nuts! | ulillillia | C Programming | 5 | 04-04-2009 09:15 PM |
| This is driving me nuts... | jesin | C Programming | 5 | 11-22-2005 05:17 AM |
| This is driving me nuts. | Matt13 | C Programming | 3 | 03-25-2004 10:55 AM |
| i can't fix it! its driving me nuts | faxtoaster | C Programming | 2 | 07-10-2003 05:46 PM |
| This compiler is driving me nuts | martin_00 | C Programming | 32 | 12-31-2002 03:25 PM |