Thread: Menu problem.

  1. #16
    Registered User
    Join Date
    Oct 2008
    Posts
    65
    Ye, sounds great, atleast if I knew how to do it. =P

    Thx for the help anyway, the exercise was just to make a menu program using enum, just wanted to evolve it a bit, but.. faaaaaaaail! ^^

    will come back to this problem later

  2. #17
    Registered User
    Join Date
    Sep 2008
    Posts
    20
    I'm not 100% sure but I think that you need ' ' around your choices.

    Like this:


    Code:
    int main()
    {
    	char choice = 'y';
    	do
    	{
    	enum difficulty{Easy = 1, Medium, Hard};
    	cout << "\t\tWelcome to my Menu.\n\n";
    	cout << "1 - Easy\n";
    	cout << "2 - Normal\n";
    	cout << "3 - Hard\n\n";
    	
    
    	int choose;
    	cout << "Choice: ";
    	cin >> choose;
    
    	switch(choose)
    	{
    *	case '1':
    		cout << "You picked the difficulty: Easy";
    		break;
    *	case '2':
    		cout << "You picked the difficulty: Normal";
    		break;
    *	case '3':
    		cout << "You picked the difficulty: Hard";
    	            break;
    	default:
    		cout << " You can only choose from 1-3, try again? (Y/N)\n: ";
    		cin >> choice;
    		system("cls");
    	
    	}
    	}
    	while(choice == 'y');
    
    	cout << "Okey then, bye.";
    
    		getch();
            return 0;
    }

  3. #18
    Banned master5001's Avatar
    Join Date
    Aug 2001
    Location
    Visalia, CA, USA
    Posts
    3,685
    Not when using cin like he has done. It will spit whatever the user typed into an integer version of the number that they input. The real problem arises when the naughty user types something other than an int.

  4. #19
    Registered User
    Join Date
    Oct 2008
    Posts
    65

    again.

    Hey again, I think I have solved this problem.
    Atleast it is working, but just wondering if there is any other way to do this?
    Seems quite tricky putting in " 'n' " between every case:

    Code:
    int main()
    {
    	char again;
    	do{
    	enum difficulty{Easy = 1, Normal, Hard};
    	cout << "\t\tWelcome to my Menu.\n\n";
    	cout << "1 - Easy\n";
    	cout << "2 - Normal\n";
    	cout << "3 - Hard\n\n";
    	
    	
    	int choose;
    	cout << "Choice: ";
    	cin >> choose;
    
    	switch(choose)
    	{
    	case Easy:
    		cout << "You picked the difficulty: Easy";
    		again = 'n';
    		break;
    	case Normal:
    		cout << "You picked the difficulty: Normal";
    		again = 'n';
    		break;
    	case Hard:
    		cout << "You picked the difficulty: Hard";
    		again = 'n';
    		break;
    		
    	default:		
    		cout << " You can only choose from 1-3, try again? (Y/N)\n: ";
    		cin >> again;
    	}
    	}while(again == 'y');
    		getch();
            return 0;
    }

  5. #20
    Registered User
    Join Date
    Mar 2007
    Posts
    416
    Code:
    int main()
    {
    	char again;
    	do{
            again = 'n';
    	enum difficulty{Easy = 1, Normal, Hard};
    	cout << "\t\tWelcome to my Menu.\n\n";
    	cout << "1 - Easy\n";
    	cout << "2 - Normal\n";
    	cout << "3 - Hard\n\n";
    	
    	
    	int choose;
    	cout << "Choice: ";
    	cin >> choose;
    
    	switch(choose)
    	{
    	case Easy:
    		cout << "You picked the difficulty: Easy";
    		break;
    	case Normal:
    		cout << "You picked the difficulty: Normal";
    		break;
    	case Hard:
    		cout << "You picked the difficulty: Hard";
    		break;
    		
    	default:		
    		cout << " You can only choose from 1-3, try again? (Y/N)\n: ";
    		cin >> again;
    	}
    	}while(again == 'y');
    		getch();
            return 0;
    }

  6. #21
    Registered User
    Join Date
    Oct 2008
    Posts
    65
    Well, ive tried that aswell, but now the loop keeps going on.
    If i pick Y on the question, the program reloops like it should, but if i put again = 'n' at the top,
    the answer will always be yes.

    so if I pick 1 again, It will say that I picked the difficulty easy and the right away reloop the program.

  7. #22
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by And3rs View Post
    Well, ive tried that aswell, but now the loop keeps going on.
    If i pick Y on the question, the program reloops like it should, but if i put again = 'n' at the top,
    the answer will always be yes.

    so if I pick 1 again, It will say that I picked the difficulty easy and the right away reloop the program.
    Except, of course, that it doesn't.

  8. #23
    Registered User
    Join Date
    Oct 2008
    Posts
    65

    ..

    Well atleast my program did that.

  9. #24
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Did you put the line where scwizzo put it? (Specifically, inside the do-while loop at the top, but not before it.)

  10. #25
    Registered User
    Join Date
    Mar 2007
    Posts
    416
    I doubt you put it inside the do-while loop since I can run that exact code and it will not loop. Like tabstop said, make sure it is inside the loop.

  11. #26
    Registered User
    Join Date
    Oct 2008
    Posts
    65
    Nope I did not :P

    thx for the help

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. A question related to strcmp
    By meili100 in forum C++ Programming
    Replies: 6
    Last Post: 07-07-2007, 02:51 PM
  2. Simple Menu Problem
    By DanC in forum C++ Programming
    Replies: 4
    Last Post: 03-15-2006, 01:33 PM
  3. Problem with Mouse Over Menu!!! HELP!!!
    By SweeLeen in forum C++ Programming
    Replies: 3
    Last Post: 02-09-2006, 02:10 AM
  4. Window - Menu problem...
    By FromHolland in forum Windows Programming
    Replies: 1
    Last Post: 02-26-2004, 03:49 PM
  5. MDI and MENU Problem
    By Marc in forum Windows Programming
    Replies: 3
    Last Post: 02-21-2004, 06:59 PM