switch.cpp 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. // switch.cpp -- using the switch statement
  2. #include <iostream>
  3. using namespace std;
  4. void showmenu(); // function prototypes
  5. void report();
  6. void comfort();
  7. int main()
  8. {
  9. showmenu();
  10. int choice;
  11. cin >> choice;
  12. while (choice != 5)
  13. {
  14. switch(choice)
  15. {
  16. case 1 : cout << "\a\n";
  17. break;
  18. case 2 : report();
  19. break;
  20. case 3 : cout << "The boss was in all day.\n";
  21. break;
  22. case 4 : comfort();
  23. break;
  24. default : cout << "That's not a choice.\n";
  25. }
  26. showmenu();
  27. cin >> choice;
  28. }
  29. cout << "Bye!\n";
  30. // cin.get();
  31. // cin.get();
  32. return 0;
  33. }
  34. void showmenu()
  35. {
  36. cout << "Please enter 1, 2, 3, 4, or 5:\n"
  37. "1) alarm 2) report\n"
  38. "3) alibi 4) comfort\n"
  39. "5) quit\n";
  40. }
  41. void report()
  42. {
  43. cout << "It's been an excellent week for business.\n"
  44. "Sales are up 120%. Expenses are down 35%.\n";
  45. }
  46. void comfort()
  47. {
  48. cout << "Your employees think you are the finest CEO\n"
  49. "in the industry. The board of directors think\n"
  50. "you are the finest CEO in the industry.\n";
  51. }