Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #include <iostream>
- #include <string>
- using namespace std;
- // Helper Strings
- string banner1 = "=====================================================";
- string banner2 = "============ Welcome to the Dining Hall =============";
- 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 voucherFoodMenu = "Please make a selection: \n (P)otato Chip $2.50, (H)am Burger $%.50, (C)hicken Rice , (B)rooklyn Pizza $4.50 \n";
- string voucherDrinkMenu = "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";
- // Helper Functions
- // Return the cost of the voucher food menu
- // parameters: voucherFoodMenu is p,h,c or b (upper or lower case)
- float getFoodCost(char voucherFoodMenu)
- {
- if(voucherFoodMenu == 'P' || voucherFoodMenu == 'p')
- return 1.50;
- else if(voucherFoodMenu == 'B' || voucherFoodMenu == 'b' || voucherFoodMenu == 'C' || voucherFoodMenu == 'c')
- return 2.00;
- else if(voucherFoodMenu == 'G' || voucherFoodMenu == 'g')
- return 2.25;
- else if(voucherFoodMenu == 'N' || voucherFoodMenu == 'n')
- return 0.0;
- }
- // Return the cost of the voucher drink menu
- // parameters: voucherDrinkMenu is a,b,c,g or n (upper or lower case)
- float getDrinkCost(char voucherDrinkMenu)
- {
- if(voucherDrinkMenu == 'P' || voucherDrinkMenu == 'p')
- return 2.50;
- else if(voucherDrinkMenu == 'H' || voucherDrinkMenu == 'h' || voucherDrinkMenu == 'C' || voucherDrinkMenu == 'c')
- return 5.50;
- else if(voucherDrinkMenu == 'B' || voucherDrinkMenu == 'b')
- return 4.50;
- return 0.0;
- }
- // Return true if the balance can cover the cost.
- // parameters: balance is the user's balance.
- // cost is the price of the item.
- bool hasSufficientFunds(float balance, float cost)
- {
- if( balance >= cost )
- {
- return true;
- }
- return false;
- }
- // function to translate the selected number (1,2,3,4) to a dollar amount ($10, $20, $50, $100).
- float receiveMoney(char bill)
- {
- float voucherMoneyInsterted = 0;
- // receive money
- if (bill == '1')
- voucherMoneyInsterted = 10.00;
- else if (bill == '2')
- voucherMoneyInsterted = 20.00;
- else if (bill == '3')
- voucherMoneyInsterted = 50.00;
- else if (bill == '4')
- voucherMoneyInsterted = voucherMoneyInsterted + 100.00;
- else {
- std::cout << "Invalid input." << std::endl;
- return 0;
- }
- return voucherMoneyInsterted;
- }
- // Function to offer more voucherFoodMenu
- // Return true if user wants more, otherwise give change.
- bool offerMoreVoucherFood()
- {
- // ask if user wants to purchase more drinks
- cout << "Add more meals?\n";
- char addMoreVoucherFoodYN;
- cin >> addMoreVoucherFoodYN;
- if (addMoreVoucherFoodYN == 'N' || addMoreVoucherFoodYN == 'n')
- return false;
- return true;
- }
- // Function to offer more voucherDrinkMenu
- // Return true if user wants more, otherwise give change.
- bool offerMoreVoucherDrinks()
- {
- // ask if user wants to purchase more drinks
- cout << "Add more drinks?\n";
- char addMoreVoucherDrinksYN;
- cin >> addMoreVoucherDrinksYN;
- if (addMoreVoucherDrinksYN == 'N' || addMoreVoucherDrinksYN == 'n')
- return false;
- return true;
- }
- // Variables
- bool done = false;
- char bill;
- char voucherFoodSelected;
- float voucherMoneyInsterted (0);
- float voucherTotalMoney (0);
- int main()
- {
- //banner
- cout<< "=====================================================" << endl;
- cout<< "============ Welcome to the Dining Hall =============" << endl;
- cout<< "=====================================================" << endl;
- //start
- while (!done){
- // Accept Payment
- bool addingMoney = true;
- while (addingMoney)
- {
- char moreMoneyYN;
- //request money
- cout<< voucherChoice << endl;
- char bill;
- cin >> bill;
- // based on input, get the monetary value
- voucherMoneyInsterted = receiveMoney(bill);
- //tell use how much money was inserted
- cout << voucherBalance << voucherMoneyInsterted << endl;
- //ask for more money
- cout << "Add more funds? (Y/N)\n";
- char addingMoneyYN;
- cin >> addingMoneyYN;
- if(addingMoneyYN == 'N' || addingMoneyYN == 'n')
- {
- // if the user did not input enough for cheapest meal quit.
- if( !hasSufficientFunds(voucherTotalMoney, 1.5) )
- {
- cout << insufficientFunds << endl;
- return 0;
- }
- addingMoney = false;
- }
- }
- //tell user the balance
- cout << voucherTotalMoney << endl;
- bool orderingVoucherFood = true;
- while (orderingVoucherFood)
- {
- //accept selection
- char voucherFoodMenu;
- cout << voucherFoodMenu << endl;
- cin >> voucherFoodMenu;
- cout << "Meal selected: " << voucherFoodMenu << endl;
- //check if balance is sufficient to cover purchase of voucher food
- float voucherFoodCost = getFoodCost(voucherFoodMenu);
- bool enoughFunds = hasSufficientFunds(voucherTotalMoney, voucherFoodCost);
- if( enoughFunds )
- {
- // Vend the drink and subtract payment
- // voucherTotalMoney = voucherTotalMoney - drinkCost;
- voucherTotalMoney -= voucherFoodCost;
- cout << "Coins/Bills: " << voucherTotalMoney << endl;
- //if enough funds for voucher food do this
- if( !hasSufficientFunds(voucherTotalMoney, 1.5))
- {
- cout << voucherTotalMoney << endl;
- return 0;
- }
- }
- else
- {
- cout << "Coins/Bills: " << voucherTotalMoney - voucherFoodCost << endl;
- cout << insufficientFunds << "\nInsufficient amount to make selection\n";
- cout << "Coins/Bills: " << voucherTotalMoney << endl;
- }
- if(!offerMoreVoucherFood())
- {
- cout << voucherTotalMoney << endl;
- done = true;
- }
- }
- done = true;
- }
- cout << "Bye!\n";
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement