Advertisement
Guest User

Untitled

a guest
Apr 23rd, 2014
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.17 KB | None | 0 0
  1. //Write a program that simulates a healthy drink machine. The program should
  2. //use functions to service arrays that store the following data.
  3.  
  4. #include <iostream>
  5. #include <string>
  6. using namespace std;
  7.  
  8. void buyDrink(int); //Max 5 per selection
  9.  
  10. int main()
  11. {
  12.  
  13. const int choices = 3; //Number of drink types
  14. string drinks[choices] = {"Green Tea - ", "\nKale Juice - ", "\nVery Berry Shake - "}; //Drink choices
  15. double drinkPrice[choices] = {1.25, 1.50 , 1.75}; //Drink prices
  16. int drinkAmount[choices] = {5,5,5}; //Amount of each in the machine
  17. int drinkType = 0;
  18. int drinksinMachine = 15;
  19. double change = 0;
  20. double moneyInserted = 0; //Money user enters
  21. double machineMade = 0; //Total machine made, initialized at 0 to accumulate.
  22.  
  23. cout << "The drinks you may purchase are: \n\n";
  24. for(int count=0; count<choices; count++) //Drink display
  25. {
  26. cout << drinks[count];
  27. cout << drinkPrice[count];
  28. }
  29.  
  30. //User decides whether to proceed with the program or to terminate it.
  31.  
  32. toupper; //Changes lowercase to uppercase
  33. char response ='y';
  34. cout << " \n\nWould you like to purchase a drink from this machine? \n";
  35. cout << "If yes type 'Y', if not type 'N' and the program will exit. \n";
  36. cin >> response;
  37.  
  38. while(toupper(response)!= 'N' && toupper(response)!= 'Y')
  39. {
  40. cout << "Please input 'N' or 'Y' "<< endl;
  41. cin >> response;
  42. }
  43. if(toupper(response) == 'N')
  44. return 0;
  45. else if (toupper(response) == 'Y')
  46. {
  47. int drinkKind;
  48. cout << "Enter 0 for Green Tea, 1 for Kale Juice, or 2 for Very Berry Shake. \n";
  49. cin >> drinkKind;
  50.  
  51. while(drinkKind != 0 && drinkKind != 1 && drinkKind != 2)
  52. {
  53. cout << "Please choose only one drink. \n";
  54. cin >> drinkKind;
  55. }
  56.  
  57. if(drinkKind == 0)
  58. cout << "You have chosen Green Tea. \n";
  59.  
  60. if(drinkKind == 1)
  61. cout << "You have chosen Kale Juice. \n";
  62.  
  63. if(drinkKind == 2)
  64. cout << "You have chosen Very Berry Shake. \n";
  65.  
  66.  
  67.  
  68. cout << "Enter the amount of money to two decimal places that you will be inserting: \n";
  69. cin >> moneyInserted;
  70.  
  71.  
  72.  
  73. if(moneyInserted>1.25 && moneyInserted <= 2.00)
  74. {
  75. cout << "You have inserted: $" << moneyInserted << endl;
  76. }
  77.  
  78. else if(moneyInserted<1.25 || moneyInserted >2.00)
  79. {
  80. cout << "This machine will not accept anything less than $1.25 or greater \nthan $2.00. Try again: \n";
  81. cin >> moneyInserted;
  82. }
  83.  
  84. change = moneyInserted - drinkPrice[drinkKind];
  85. if(change>0)
  86. {
  87. cout << "Your change is: $" << change << endl;
  88.  
  89. machineMade+= moneyInserted-change;
  90. drinksinMachine--;
  91.  
  92. cout << "This machine has accumulated: " << machineMade << endl;
  93. }
  94. else if(change<0)
  95. {
  96. cout << "You do not have enough money." << endl;
  97. cout << "Enter new amount." << endl;
  98. cin >> moneyInserted;
  99. }
  100. else
  101. {
  102. cout << "You have no change. Enjoy your drink! \n";
  103. }
  104. }
  105. return 0;
  106.  
  107. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement