// This program uses a do-while loop in a menu.
// Constants for menu choices
constint COFFEE_CHOICE = 'A',
TEA_CHOICE = 'B',
HOT_CHOCOLATE_CHOICE = 'C',
CAPPUCCINO_CHOICE = 'D',
EXIT_CHOICE = 'E';
// Constants drink prices
constdouble COFFEE = 1.00,
TEA = 0.75,
HOT_CHOCOLATE = 1.25,
int choice; // Menu choice
int number; // Number of cups
double charges; // Monthly charges
// Output formatting.
cout << fixed << showpoint << setprecision(2);
// Display the drink menu.
cout << "\n\t\tHot Beverage Menu\n\n"
<< "A. Coffee $1.00\n"
<< "B. Tea $ .75\n"
<< "C. 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.
charges = number * COFFEE;
charges = number * TEA;
charges = number * HOT_CHOCOLATE;
charges = number * CAPPUCCINO;
// Display the tolal charges.
cout << "Your grand total is $" << charges << endl;
} while (choice != EXIT_CHOICE);
It is good practice to declare each variable on it's own line. Your code looks innocent enough, but I have a vague idea that the qualifiers like constonly apply to the first variable & not to the rest of them. I don't have a copy of the standard with me at the moment, maybe someone could verify this?
Even if I am wrong, it is still good practice to declare & initialise 1 variable per line.