Having issues making a menu that will subtotal and then display a grand total. My professor is no help. It would be awesome if anyone can point me in the right direction. Because i have no idea why its not working.
The program works fine until I get to the grand total, then it will not add together all the orders placed. Please help.
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
// Constants for menu choices
const int COFFEE_CHOICE = 'A',
TEA_CHOICE = 'B',
HOT_CHOCOLATE_CHOICE = 'C',
CAPPUCCINO_CHOICE = 'D',
EXIT_CHOICE = 'E';
// Constants drink prices
const double COFFEE = 1.00,
TEA = 0.75,
HOT_CHOCOLATE = 1.25,
CAPPUCCINO= 2.50;
// Variables
char choice; // Menu choice
int number; // Number of cups
double charges; // Monthly charges
double TOTAL = 0.0;
// Output formatting.
cout << fixed << showpoint << setprecision(2);
do
{
// Display the drink menu.
cout << "\n\t\tHot Beverage Menu\n\n"
<< "A. Coffee $1.00\n"
<< "B. Tea $ .75\n"
<< "C. Hot Chocolate $1.25\n"
<< "D. Cappuccino $2.50\n"
<< "E. Exit\n\n"
<< "Please enter your choice: ";
cin >> choice;
// Validate the menu selection.
while (choice < COFFEE_CHOICE || choice > EXIT_CHOICE)
{
cout << "Please enter a valid selection: ";
cin >> choice;
}
// Validate and process the user's choice.
if (choice != EXIT_CHOICE)
{
// Get the number of cups.
cout << "How many cups would you like? ";
cin >> number;
// Respond to menu selection.
switch (choice)
{
case COFFEE_CHOICE:
charges = number * COFFEE;
break;
case TEA_CHOICE:
charges = number * TEA;
break;
case HOT_CHOCOLATE_CHOICE:
charges = number * HOT_CHOCOLATE;
break;
case CAPPUCCINO_CHOICE:
charges = number * CAPPUCCINO;
}
// Display the total charges.
cout << "Your sub total is $" << charges << endl;
}
else if (choice == EXIT_CHOICE)
{
TOTAL += charges;
cout << "Your grand total is $" << TOTAL << endl;
}
}
while (choice != EXIT_CHOICE);
return 0;
}