fork download
  1.  
  2.  
  3. #include <iostream>
  4. #include <cstdlib>
  5. using namespace std;
  6.  
  7. void flushCin();
  8. int menu();
  9. int game();
  10. int score();
  11. int exit();
  12. //int reserved();
  13.  
  14.  
  15. void flushCin() {
  16. cin.clear(); //reset to good
  17. while (cin.get() != '\n');
  18. }
  19. int game() {
  20. cout << "game" << endl;
  21. return 0;
  22.  
  23. }
  24.  
  25. int score(){
  26. cout << "score" << endl;
  27. return 0;
  28. }
  29.  
  30. int exit() {
  31. cout << "exit" << endl;
  32. return 0;
  33. }
  34.  
  35. //int reserved(){
  36. //
  37. //}
  38.  
  39. int menu(){
  40. int enter;
  41. bool should_exit = false;
  42. do {
  43. cout << "how do you want to start? " << endl;
  44. cout << "1 - start game" << endl;
  45. cout << "2 - highscore " << endl;
  46. //cout << "3 - reserved for later " << endl;
  47. cout << "4 - exit " << endl;
  48.  
  49. cin >> enter;
  50. switch (enter) {
  51. case 1 :
  52. game();
  53. break;
  54. case 2 :
  55. score();
  56. break;
  57. //case 3 : reserved(); break;
  58. case 4 :
  59. should_exit = true;
  60. break;
  61. default :
  62. cout << "not a valid option, again: " << endl;
  63. void flushCin();
  64. cin >> enter;
  65. } //end of switch
  66. }while (should_exit == false);
  67.  
  68. }//end of menu();
  69.  
  70. int main(){
  71. menu();
  72. cout << "Exited menu" << endl;
  73. return 0;
  74. }
  75.  
  76.  
Success #stdin #stdout 0s 3304KB
stdin
1
2
5
4
stdout
how do you want to start? 
1 - start game
2 - highscore 
4 - exit 
game
how do you want to start? 
1 - start game
2 - highscore 
4 - exit 
score
how do you want to start? 
1 - start game
2 - highscore 
4 - exit 
not a valid option, again: 
how do you want to start? 
1 - start game
2 - highscore 
4 - exit 
Exited menu