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
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
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; }
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.
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; }
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; }
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.
Well atleast my program did that.
Did you put the line where scwizzo put it? (Specifically, inside the do-while loop at the top, but not before it.)
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.
Nope I did not :P
thx for the help