Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2019
87
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.97 KB | None | 0 0
  1. // Lec10.cpp
  2. #include <iostream>
  3. #include <iomanip>
  4. using namespace std;
  5.  
  6.  
  7. enum statements { InsertMoney, WaitForSelection, CheckInventory, ReturnTotal };
  8. double sodacost = 0.75;
  9. statements state = InsertMoney;
  10.  
  11. int main()
  12. {
  13. int coke = 2;
  14. int pepsi = 2;
  15.  
  16. while (true) {
  17. switch (state) {
  18.  
  19.  
  20. case InsertMoney:
  21. cout << "Please Insert Money or press 0 for a refund" << endl;
  22. double money;
  23. cin >> money;
  24.  
  25. if (money == 0) {
  26. state = ReturnTotal;
  27. }
  28.  
  29. else if (money >= sodacost) {
  30. double change = money - sodacost;
  31. cout << "Your change is " << change << endl;
  32. state = WaitForSelection;
  33. }
  34.  
  35. else if (money < sodacost) {
  36. cout << "Not enough money" << endl;
  37. state = InsertMoney;
  38. }
  39.  
  40. break;
  41.  
  42.  
  43. case WaitForSelection:
  44. cout << "Please press 1 for Coke, 2 for Pepsi, or 9 for refund: " << endl;
  45. int decision;
  46. cin >> decision;
  47.  
  48. if (decision == 1) {
  49. state = CheckInventory;
  50. }
  51.  
  52. else if (decision == 2) {
  53. state = CheckInventory;
  54. }
  55.  
  56. else if (decision == 9) {
  57. state = ReturnTotal;
  58. }
  59. break;
  60.  
  61.  
  62. case CheckInventory:
  63. cout << "The inventory is currently being checked. Please wait a moment" << endl;
  64.  
  65. if (decision == 1) {
  66. if (coke > 0) {
  67. coke--;
  68. cout << "Please enjoy your Coke. I wish I could drink soda" << endl;
  69. state = InsertMoney;
  70. }
  71. else if (coke == 0) {
  72. cout << "We are all sold out of Coke. Sorry" << endl;
  73. state = ReturnTotal;
  74. }
  75. }
  76. else if (decision == 2) {
  77. if (pepsi > 0) {
  78. pepsi--;
  79. cout << "Please enjoy your Pepsi. It's not like I wanted some Pepsi" << endl;
  80. state = InsertMoney;
  81. }
  82. else if (pepsi == 0) {
  83. cout << "We are all sold out of Pepsi. Sorry" << endl;
  84. state = ReturnTotal;
  85. }
  86. }
  87. break;
  88.  
  89. case ReturnTotal:
  90. cout << "Your return is: $" << money << endl;
  91. state = InsertMoney;
  92. break;
  93. }
  94. }
  95. system("pause");
  96. return 0;
  97. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement