Advertisement
Guest User

Untitled

a guest
Dec 11th, 2019
165
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 3.52 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. bool hasSufficientFunds( float cost, float balance)
  6.  
  7. {
  8.  
  9.     return (cost <= balance);
  10.  
  11. }
  12.  
  13. //BEGIN
  14.  
  15. int main()
  16.  
  17. {
  18.  
  19.     char input; //user inputs
  20.     int balance = 0; //amount of money inserted
  21.     float minCost = 1.5; // min amount to make a purchase
  22.     string voucherChoice = "Please Choose Your Dining Voucher: \n (1) $10, (2) $20, (3) $50, (4) $100 \n";
  23.     string voucherBalance = "You've inserted: \n";
  24.     string voucherMoreMoney = "Add more funds? (Y/N)";
  25.     string foodMenu = "Please make a selection: \n (P)otato Chip $2.50, (H)am Burger $2.50, (C)hicken Rice , (B)rooklyn Pizza $4.50 \n";
  26.     string drinkMenu = "Select your beverages: \n (A)quaVenna $1.50, (B)epsi $2.00, (C)ool Cola $2.00, (G)atorade $2.25, (N)o Beverage \n";
  27.     string insufficientFunds = "Insufficient amount to make selection \n";
  28.     string changeProvided = "Enjoy your meals \n";
  29.  
  30. //greeting for venting machine
  31.     cout<<"=====================================================" <<endl;
  32.     cout<<"============ Welcome to the Dining Hall =============" <<endl;
  33.     cout<<"=====================================================" <<endl;
  34.  
  35.     while( true )
  36.  
  37. {
  38.  
  39.     cout<< voucherChoice;
  40.     cin>> input;
  41.  
  42.     if (input == '1')
  43.         balance += 10.00;
  44.  
  45.     else if  (input == '2')
  46.         balance += 20.00;
  47.  
  48.     else if  (input == '3')
  49.         balance += 50.00;
  50.  
  51.     else if  (input == '4')
  52.         balance = balance += 100.00;
  53.  
  54.     cout<< voucherBalance << balance << endl;
  55.  
  56.     cout<< voucherMoreMoney;
  57.     cin>> input;
  58.  
  59.     if(input == 'N' || input == 'n')
  60.  
  61.     break;
  62.  
  63. }
  64. //balance check
  65.  
  66.     if( balance == 0)
  67.  
  68.     {
  69.  
  70.         cout<< insufficientFunds << endl;
  71.  
  72.         return 0;
  73.  
  74.     }
  75.  
  76.  
  77. //Voucher meal menu loop
  78.  
  79.     minCost = 2.5;
  80.  
  81.     while( true )
  82.  
  83. {
  84.  
  85.     if (balance < minCost)
  86.  
  87.     break;
  88.  
  89.  
  90.     cout<< foodMenu;
  91.     cin>> input;
  92.  
  93.         if(input == 'P' || input == 'p')
  94.  
  95.             balance -= 2.5;
  96.  
  97.         if(input == 'H' || input == 'h')
  98.  
  99.             balance -= 5.5;
  100.  
  101.         if(input == 'C' || input == 'c')
  102.  
  103.             balance -= 5.5;
  104.  
  105.         if(input == 'B' || input == 'b')
  106.  
  107.             balance -= 4.5;
  108.  
  109.         if(input == 'N' || input == 'n')
  110.  
  111.             balance -= 0.0;
  112.  
  113.         cout<< "Coins/bills: " << balance << endl;
  114.  
  115.  
  116.         if( balance >= minCost)
  117.  
  118.         {
  119.  
  120.  
  121.             cout<< voucherMoreMoney;
  122.  
  123.             cin>> input;
  124.  
  125.  
  126.             if(input == 'N' || input == 'n')
  127.  
  128.             break;
  129.  
  130. }
  131. }
  132.  
  133. //Voucher drink menu Loop
  134.  
  135.  
  136.     minCost = 1.5;
  137.  
  138.     while( true )
  139.  
  140. {
  141.  
  142.         if( balance < minCost )
  143.  
  144.         {
  145.  
  146. //take change
  147.  
  148.             break;
  149.  
  150.         }
  151.  
  152.  
  153.         cout<< drinkMenu;
  154.         cin>> input;
  155.  
  156.         if(input == 'A' || input == 'p')
  157.  
  158.             balance -= 1.5;
  159.  
  160.         if(input == 'B' || input == 'h')
  161.  
  162.             balance -= 2.0;
  163.  
  164.         if(input == 'C' || input == 'c')
  165.  
  166.             balance -= 2.0;
  167.  
  168.         if(input == 'G' || input == 'b')
  169.  
  170.             balance -= 2.25;
  171.  
  172.         if(input == 'N' || input == 'n')
  173.  
  174.             balance -= 0.0;
  175.  
  176. //has enough funds
  177.     int cost = 0;
  178.  
  179.  
  180.         if( hasSufficientFunds(cost, balance))
  181.  
  182.         {
  183.  
  184.             balance -= cost;
  185.  
  186.         }
  187.  
  188.         else
  189.  
  190.         {
  191.  
  192. //error message
  193.  
  194.             cout<< insufficientFunds << balance << endl ;
  195.  
  196.             return 0;
  197.  
  198.         }
  199.  
  200.  
  201.         cout<< "Coins/bills: " << balance << endl;
  202.  
  203.  
  204.         if( balance < minCost )
  205.  
  206.         {
  207.  
  208. //can't buy anything so take change
  209.  
  210.         break;
  211.  
  212.         }
  213.  
  214.  
  215.         cout<< "Would you like more drinks (Y/N)? " ;
  216.  
  217.         cin>> input;
  218.  
  219.  
  220.         if(input == 'N' || input == 'n')
  221.  
  222.             break;
  223.  
  224.  
  225.     }
  226.  
  227.  
  228.  
  229. //your change is
  230.  
  231.     cout<< "Take your change: " << balance << endl;
  232.  
  233.  
  234.  
  235. //END
  236.     cout<< changeProvided;
  237. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement