Advertisement
avr39ripe

cppSimpleMenuTemplate

Mar 10th, 2021
181
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.77 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. int main()
  4. {
  5.     char  action{ 'x' };
  6.  
  7.     do
  8.     {
  9.         std::cout << "Action 1\t- a\n";
  10.         std::cout << "Action 2\t- b\n";
  11.         std::cout << "Action 3\t- c\n";
  12.         std::cout << "Exit\t\t- x\n";
  13.  
  14.         std::cout << "\nEnter a,b,c to select action or x to exit\n";
  15.  
  16.         std::cin >> action;
  17.  
  18.         switch (action)
  19.         {
  20.         case 'a':
  21.             std::cout << "User selected Action 1\n";
  22.             std::cout << "Booom!\n";
  23.             break;
  24.         case 'b':
  25.             std::cout << "User selected Action 2\n";
  26.             std::cout << "OoopS!\n";
  27.             break;
  28.         case 'c':
  29.             std::cout << "User selected Action 3\n";
  30.             std::cout << "Hello!\n";
  31.             break;
  32.         case 'x':
  33.             std::cout << "Exiting...\n";
  34.             break;
  35.         default:
  36.             std::cout << "Incorrect menu item! Try again!\n";
  37.         }
  38.     } while (action != 'x');
  39.  
  40.     return 0;
  41. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement