driving me nuts

This is a discussion on driving me nuts within the C++ Programming forums, part of the General Programming Boards category; Hi all, I cant show you any code cos im at work, but hes what im tryng to do.... I ...

  1. #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

  2. #2
    End Of Line Hammer's Avatar
    Join Date
    Apr 2002
    Posts
    6,231
    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]

  3. #3
    &TH of undefined behavior Fordy's Avatar
    Join Date
    Aug 2001
    Posts
    5,789
    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;
    }

  4. #4
    Registered User
    Join Date
    Oct 2002
    Posts
    59
    cheers guys

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. An error is driving me nuts!
    By ulillillia in forum C Programming
    Replies: 5
    Last Post: 04-04-2009, 09:15 PM
  2. This is driving me nuts...
    By jesin in forum C Programming
    Replies: 5
    Last Post: 11-22-2005, 04:17 AM
  3. This is driving me nuts.
    By Matt13 in forum C Programming
    Replies: 3
    Last Post: 03-25-2004, 09:55 AM
  4. i can't fix it! its driving me nuts
    By faxtoaster in forum C Programming
    Replies: 2
    Last Post: 07-10-2003, 05:46 PM
  5. This compiler is driving me nuts
    By martin_00 in forum C Programming
    Replies: 32
    Last Post: 12-31-2002, 02:25 PM

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