C Board  

Go Back   C Board > General Programming Boards > C++ Programming

Reply
 
LinkBack Thread Tools Display Modes
Old 10-07-2002, 03:18 AM   #1
Registered User
 
Join Date: Oct 2002
Posts: 59
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
boontune is offline   Reply With Quote
Old 10-07-2002, 03:39 AM   #2
End Of Line
 
Hammer's Avatar
 
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   Reply With Quote
Old 10-07-2002, 04:13 AM   #3
&TH of undefined behavior
 
Fordy's Avatar
 
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   Reply With Quote
Old 10-07-2002, 04:35 AM   #4
Registered User
 
Join Date: Oct 2002
Posts: 59
cheers guys
boontune is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Forum Jump

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


All times are GMT -6. The time now is 09:21 AM.


Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.3.2

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22