Advertisement
Guest User

Untitled

a guest
Dec 11th, 2019
146
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. //Voucher drink menu Loop
  133.  
  134.  
  135.     minCost = 1.5;
  136.  
  137.     while( true )
  138.  
  139. {
  140.  
  141.         if( balance < minCost )
  142.  
  143.         {
  144.  
  145. //take change
  146.  
  147.             break;
  148.  
  149.         }
  150.  
  151.  
  152.         cout<< drinkMenu;
  153.         cin>> input;
  154.  
  155.         if(input == 'A' || input == 'p')
  156.  
  157.             balance -= 2.5;
  158.  
  159.         if(input == 'B' || input == 'h')
  160.  
  161.             balance -= 5.5;
  162.  
  163.         if(input == 'C' || input == 'c')
  164.  
  165.             balance -= 5.5;
  166.  
  167.         if(input == 'G' || input == 'b')
  168.  
  169.             balance -= 4.5;
  170.  
  171.         if(input == 'N' || input == 'n')
  172.  
  173.             balance -= 0.0;
  174.  
  175. //has enough funds
  176.     int cost = 0;
  177.  
  178.  
  179.         if( hasSufficientFunds(cost, balance))
  180.  
  181.         {
  182.  
  183.             balance -= cost;
  184.  
  185.         }
  186.  
  187.         else
  188.  
  189.         {
  190.  
  191. //error message
  192.  
  193.             cout<< insufficientFunds << balance << endl ;
  194.  
  195.             return 0;
  196.  
  197.         }
  198.  
  199.  
  200.         cout<< "Coins/bills: " << balance << endl;
  201.  
  202.  
  203.         if( balance < minCost )
  204.  
  205.         {
  206.  
  207. //can't buy anything so take change
  208.  
  209.         break;
  210.  
  211.         }
  212.  
  213.  
  214.         cout<< "Would you like more drinks (Y/N)? " ;
  215.  
  216.         cin>> input;
  217.  
  218.  
  219.         if(input == 'N' || input == 'n')
  220.  
  221.             break;
  222.  
  223.  
  224.     }
  225.  
  226.  
  227.  
  228. //your change is
  229.  
  230.     cout<< "Take your change: " << balance << endl;
  231.  
  232.  
  233.  
  234. //END
  235.     cout<< changeProvided;
  236. }
  237.  
  238.  
  239. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement