Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- using namespace std;
- bool hasSufficientFunds( float cost, float balance)
- {
- return (cost <= balance);
- }
- //BEGIN
- int main()
- {
- char input; //user inputs
- int balance = 0; //amount of money inserted
- float minCost = 1.5; // min amount to make a purchase
- string voucherChoice = "Please Choose Your Dining Voucher: \n (1) $10, (2) $20, (3) $50, (4) $100 \n";
- string voucherBalance = "You've inserted: \n";
- string voucherMoreMoney = "Add more funds? (Y/N)";
- 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";
- 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";
- string insufficientFunds = "Insufficient amount to make selection \n";
- string changeProvided = "Enjoy your meals \n";
- //greeting for venting machine
- cout<<"=====================================================" <<endl;
- cout<<"============ Welcome to the Dining Hall =============" <<endl;
- cout<<"=====================================================" <<endl;
- while( true )
- {
- cout<< voucherChoice;
- cin>> input;
- if (input == '1')
- balance += 10.00;
- else if (input == '2')
- balance += 20.00;
- else if (input == '3')
- balance += 50.00;
- else if (input == '4')
- balance = balance += 100.00;
- cout<< voucherBalance << balance << endl;
- cout<< voucherMoreMoney;
- cin>> input;
- if(input == 'N' || input == 'n')
- break;
- }
- //balance check
- if( balance == 0)
- {
- cout<< insufficientFunds << endl;
- return 0;
- }
- //Voucher meal menu loop
- minCost = 2.5;
- while( true )
- {
- if (balance < minCost)
- break;
- cout<< foodMenu;
- cin>> input;
- if(input == 'P' || input == 'p')
- balance -= 2.5;
- if(input == 'H' || input == 'h')
- balance -= 5.5;
- if(input == 'C' || input == 'c')
- balance -= 5.5;
- if(input == 'B' || input == 'b')
- balance -= 4.5;
- if(input == 'N' || input == 'n')
- balance -= 0.0;
- cout<< "Coins/bills: " << balance << endl;
- if( balance >= minCost)
- {
- cout<< voucherMoreMoney;
- cin>> input;
- if(input == 'N' || input == 'n')
- break;
- }
- //Voucher drink menu Loop
- minCost = 1.5;
- while( true )
- {
- if( balance < minCost )
- {
- //take change
- break;
- }
- cout<< drinkMenu;
- cin>> input;
- if(input == 'A' || input == 'p')
- balance -= 2.5;
- if(input == 'B' || input == 'h')
- balance -= 5.5;
- if(input == 'C' || input == 'c')
- balance -= 5.5;
- if(input == 'G' || input == 'b')
- balance -= 4.5;
- if(input == 'N' || input == 'n')
- balance -= 0.0;
- //has enough funds
- int cost = 0;
- if( hasSufficientFunds(cost, balance))
- {
- balance -= cost;
- }
- else
- {
- //error message
- cout<< insufficientFunds << balance << endl ;
- return 0;
- }
- cout<< "Coins/bills: " << balance << endl;
- if( balance < minCost )
- {
- //can't buy anything so take change
- break;
- }
- cout<< "Would you like more drinks (Y/N)? " ;
- cin>> input;
- if(input == 'N' || input == 'n')
- break;
- }
- //your change is
- cout<< "Take your change: " << balance << endl;
- //END
- cout<< changeProvided;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement