I NEED HELP ASAP!!!!!!!!

Hi, im having trouble debugging my menu driven program that involves primarily functions, but also includes loops, switch, and if statements.

Heres my error message----->

In function ‘int main()’:
krusty.cpp:45:7: error: expected ‘;’ before ‘menu’
menu();
^


and heres my code:



#include <iostream>
#include <iomanip>
using namespace std;

double ordertotal(int,int,int,int);//prototype for order total

void menu()//function for displaying menu
{
cout << "----------- Menu -----------\n
1. Krabby Patty ...... $3.50\n
2. Barnicle Fries .... $1.50\n
3. Kelp Shake ........ $1.00\n
4. Krusty Krab Pizza . $5.00\n";
}



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";
}
Last edited on
Please use code tags to make your code more readable. ;-)

Look at the error-message: krusty.cpp:45:7: error: expected ‘;’ before ‘menu’

It translates to: "Look at the line that is above this line, and add a semicolon at the end of it."

Given these are the lines, it should be easy for you to figure where to place it. ;-)

1
2
cout << "This isn't on the menu! Try again."
menu();

Thank you. What are code tags, though. Never heard of them. Are you talking about the color coding/syntax theme?
Last edited on
Topic archived. No new replies allowed.