I need to make a restaurant bill calculator program that allows people to choose from a list of menu items (a function) until they have everything they've wanted to order and then calculate the total when they are finished selecting from a list. Then it takes the amount they tender and subtracts the total plus tax and tip to calculate change.
I've found several ideas and similar programs here and on other places but nothing that has given me a good enough idea of how to get this finalized. I have the program coded but I can't figure out how to take the running total and keep accumulating it until the user enters "8". I have a functioning program but it totals after each selection instead of keeping a running total and calcuating it when the user hits the "8" key to end.
Take a look below and see if you can point my in the right direction if you would. Basically this assignment is about functions so we're asked to use functions to display the menu and calculate the total.
#include <iostream>
#include <iomanip>
using namespace std;
// Function Prototypes
void showMenu();
void showFees(double, int);
int main()
{
int choice; //To Hold Menu Choice
double quantity = 1;
//contants for menu choices
const int hamburgerChoice = 1;
const int hotdogChoice = 2;
const int peanutsChoice = 3;
const int popcornChoice = 4;
const int sodaChoice = 5;
const int chipsChoice = 6;
const int waterChoice = 7;
const int endOrderChoice = 8;
//constants for menu prices
const double hamburger = 6.00;
const double hotdog = 4.50;
const double peanuts = 3.75;
const double popcorn = 5.50;
const double soda = 2.80;
const double chips = 1.00;
const double water = 2.00;
//set precision
cout << fixed << showpoint << setprecision(2);
do
{
//display menu and get user choice
showMenu();
cin >> choice;
//validate choice
while (choice < hamburgerChoice || choice > endOrderChoice)
{
cout << "Please enter a valid menu choice: ";
cin >> choice;
}
//if the user does not want to quit proceed
if (choice != endOrderChoice)
{
//display fees
switch (choice)
{
case hamburgerChoice:
showFees(hamburger, quantity);
break;
case hotdogChoice:
showFees(hotdog, quantity);
break;
case peanutsChoice:
showFees(peanuts, quantity);
break;
case popcornChoice:
showFees(popcorn, quantity);
break;
case sodaChoice:
showFees(soda, quantity);
break;
case chipsChoice:
showFees(chips, quantity);
break;
case waterChoice:
showFees(water, quantity);
break;
}
}
}
while (choice != endOrderChoice);
system("pause");
return 0;
}
//*************************************************************
//Definition of function showMenu which displays the menu **
//*************************************************************
void showMenu()
{
cout << "\n\t\tBaseball Game Snacks" << endl;
cout << "1. Hamburger \t$6.00"<< endl;
cout << "2. Hotdog \t\t$4.50" << endl;
cout << "3. Peanuts \t\t$3.75" << endl;
cout << "4. Popcorn \t\t$5.50" << endl;
cout << "5. Soda \t\t$2.80" << endl;
cout << "6. Chips \t\t$1.00"<< endl;
cout << "7. Water \t\t$2.00" << endl;
cout << "8. END ORDER" << endl;
cout << "Please enter your menu choice: ";
}
//************************************************************
//Definition of function showFees which caculates the total **
//bill **
//************************************************************
void showFees(double itemCost, int quantity)
{
double amtTendered;
double totalBill = (itemCost * quantity);
double taxRate = .065;
double tipRate = .20;
double tip = (totalBill * tipRate);
double tax = (totalBill * taxRate);
double amountDue = (totalBill + tax + tip);
cout << "Total Bill: $" << totalBill << endl;
cout << "Tax: $" << tax << endl;
cout << "Tip: $" << tip << endl;
cout << "Total Amount Due: $" << amountDue << endl;
cout << "Enter ammount tendered: $";
cin >> amtTendered;
double changeDue = amtTendered - amountDue;
cout << "Change Due: $" << changeDue << endl;
}