int main()
{
int option; //To hold a menu choice
int zero1 = 0; //To record cumulative amount of OPTION1 starting at 0
int zero2 = 0; //To record cumulative amount of OPTION2 starting at 0
int zero3 = 0; //To record cumulative amount of OPTION3 starting at 0
int zero4 = 0; //To record cumulative amount of OPTION4 starting at 0
int amount; //To hold an amount
//Constants for menu choices
const int OPTION1 = 1,
OPTION2 = 2,
OPTION3 = 3,
OPTION4 = 4,
OPTIONQUIT = 0;
menu();
cout << "\nWhat would you like? (Enter 0 to finish order!): ";
cin >> option;
while (option > OPTION4 || option < OPTIONQUIT)//invalid menu selection
{
cout << "This isn't on the menu! Try again."
menu();
cin >> option;
}
if (option == OPTIONQUIT)//quit menu selection
{
cout << "Guess you aren't hungry.\n";
return 0;
}
while (option != OPTIONQUIT)//valid menu selection not including quit
{
switch (option)//switch block for valid menu choices
{
case OPTION1:
cout << "How many: ";
cin >> amount;
while (amount < 0)//invalid amount
{
cout << "You can't order a negative amount of food!\n
try again: ";
cin >> amount;
}
zero1 += amount;
break;
case OPTION2:
cout << "How many: ";
cin >> amount;
while (amount < 0)//invalid amount
{
cout << "You can't order a negative amount of food!\n
try again: ";
cin >> amount;
}
zero2 += amount;
break;
case OPTION3:
cout << "How many: ";
cin >> amount;
while (amount < 0)//invalid amount
{
cout << "You can't order a negative amount of food!\n
try again: ";
cin >> amount;
}
zero3 += amount;
break;
case OPTION4:
cout << "How many: ";
cin >> amount;
while (amount < 0)//invalid amount
{
cout << "You can't order a negative amount of food!\n
try again: ";
cin >> amount;
}
zero4 += amount;
break;
}
}
cout << "Your order:\n";
if (zero1 != 0)//if statements for displaying amount of each menu choice
cout << zero1 << "krabby patties\n";
if (zero2 != 0)
cout << zero2 << "barnicle fries\n";
if (zero3 != 0)
cout << zero3 << "kelp shakes\n";
if (zero4 != 0)
cout << zero4 << "krusty krab pizzas\n";
ordertotal(int zero1,int zero2,int zero3,int zero4);//call function to display order total and invoke exit message
return 0;
}
double ordertotal(int num1,int num2,int num3,int num4)//function definition for calculating order total.
{
//Constants for menu rates
const double RATE_KRABBY = 3.50,
RATE_BARNICLE = 1.50,
RATE_KELP = 1.00,
RATE_PIZZA = 5.00;
double total_price; //To hold total price
total_price = (num1 * RATE_KRABBY) + (num2 * RATE_BARNICLE) + (num3 * RATE_KELP) + (num4 * RATE_PIZZA);
cout << "\nYour total is $" << total_price << "\nEnjoy the food!\n";
}