PDA

View Full Version : Menu program


lvpnk
05-05-2009, 03:13 AM
Hey everyone, I've been working on this program for a menu using functions and i keep getting the error that my variables tot1,tot2,tot3,tot4,tot5,customers aren't declared. But I thought that I've made all the necessary declarations. I'm using the bloodshed dev c++ compiler. thanks for any help, here's my code.

#include<iostream>
#include<fstream>
#include<iomanip>
#include<cctype>
#include<cstdlib>
#include"another.cpp"

using namespace std;

ofstream outs; //Declare outs globally so that you can access it in the
//functions directly


int main()
{


int num1, //number of Buffalo Wings ordered by a single customer
num2, //number of Super Burgers ordered by a single customer
num3, //number of Italian Sandwiches ordered by a single customer
num4, //number of Shrimp Nuggets ordered by a single customer
num5, //number of Veggie Supremes ordered by a single customer
customers; //number of customers
int total1, //total number of Buffalo Wings ordered for the day
total2, //total number of Super Burgers ordered for the day
total3, //total number of Italian Sandwiches ordered for the day
total4, //total number of Shrimp Nuggets ordered for the day
total5; //total number of Veggie Supremes ordered for the day



//Function Prototypes
void describe_program();
void display_menu();
void get_order(int& num1,int& num2,int& num3, int& num4, int& num5);
void compute_display_bill(int num1, int num2, int num3, int num4, int num5);
void compute_totals(int num1, int num2, int num3, int num4, int num5 );
bool another();
void summary( int customers);

//open external file
outs.open("food_court.txt",ios::app);

describe_program();

//Initialize variables

total1 = 0, total2 = 0, total3 = 0, total4 = 0, total5 = 0, customers = 0;

do //processing of a customer
{
customers++;
//update customer count
display_menu();
//display the menu
get_order(num1,num2,num3, num4,num5);
//get order from the customer
compute_display_bill(num1, num2,num3, num4, num5);
//Indicate the customer number at external file
compute_totals(num1,num2,num3,num4, num5);
//compute and display the customer's bill at the screen and external file

//compute totals so far


}while(another()); //while there is another customer
summary(customers);
//print a daily summary at the screen and external file

outs.close();
system("PAUSE");
return 0;
}


//Define functions here

//You write the code! It's similar to the function again()


void describe_program()
{

cout<<"This program will ask you to place an order at a fast food restaurant.\n"
<<"There are 5 items on the menu including buffalo wings, a Super burger,\n"
<<"an Italian sandwich, shrimp nuggets and a veggie supreme. You will\n"
<<"enter your choice according to the corresponding order numbers on each\n"
<<"item. You may order as many items as you like. When the days orders\n"
<<"are complete, enter 0 and the program will calculate the total amount\n"
<<"of money, items, amount each item cost and the total number of \n"
<<"customers for that day. All of this information will be shown at the \n"
<<"screen and sent to the external file food_court.txt.\n\n";
//You write the code

return;
}

void display_menu()
{
cout<<"Welcome to the best restaurant! Please have a look at our menu and make\n"
<<"your choice.\n"
<<"1 - Buffalo Wings - $6.95\n"
<<"2 - Super Burger - $5.75\n"
<<"3 - Italian Sandwich - $7.25\n"
<<"4 - Shrimp Nuggets - $8.95\n"
<<"5 - Veggie Supreme - $4.95\n";

//Display menu of items and get order
//You write the code
return;
}


void get_order(int& num1,int& num2,int& num3, int& num4, int& num5)
{
const int Sentinel = 0;
int choice, //menu choice made by customer
num; //number of a particular food item ordered by a customer
cout<<"Which item would like like? Please enter the item number:";
cin>>choice;

//Initialize num1, num2 etc. You write the code!
num1 = 0, num2 = 0, num3 = 0, num4 = 0, num5 = 0;

while (choice!=Sentinel)
{
switch (choice)
{
case 1:
cout<<"How many of this item would you like? Please enter an amount:";
cin>>num;
num1+=num;
break;
case 2:
cout<<"How many of this item would you like? Please enter an amount:";
cin>>num;
num2+=num;
break;
case 3:
cout<<"How many of this item would you like? Please enter an amount:";
cin>>num;
num3+=num;
break;
case 4:
cout<<"How many of this item would you like? Please enter an amount:";
cin>>num;
num4+=num;
break;
case 5:
cout<<"How many of this item would you like? Please enter an amount:";
cin>>num;
num5+=num;
break;

default: cout<<"You have entered an invalid menu item! Please enter a valid\n"
<<"number\n";
}
cout<<"Please enter an item number or 0 to complete your order:";
cin>>choice;
//Process customer order. Use a while loop with a senatinel value of 0.
//Use a switch statement to ask how many of the selection the customer
//wants and update the number of that food item by the number ordered by the
//customer
//You write the code!

return;
}



void compute_display_bill(int num1, int num2, int num3, int num4, int num5);
{


const double price1 = 6.95, //price of Buffalo Wings
price2 = 5.75, //price of Super Burgers
price3 = 7.25, //price of Italian Sandwich
price4 = 8.95, //price of Shrimp Nuggets
price5 = 4.95; //price of Veggie Supreme

double cost1, //cost of num1 Buffalo Wings
cost2, //cost of num2 Super Burgers
cost3, //cost of num3 Italian Sandwiches
cost4, //cost of num4 Shrimp Nuggets
cost5, //cost of num5 Veggie Supremes
totcost; //total cost of the order


cost1 = num1*price1;

cost2 = num2*price2;

cost3 = num3*price3;

cost4 = num4*price4;

cost5 = num5*price5;

totcost = cost1+cost2+cost3+cost4+cost5;

cout<<"The total cost for this order is "<<totcost<<".\n";

//You write the code that computes the above costs and displays them
//at the screen and the external file!
return;
}

void compute_totals(int num1, int num2, int num3, int num4, int num5,
int& tot1, int& tot2, int& tot3, int& tot4, int& tot5);

{
tot1+=num1;
tot2+=num2;
tot3+=num3;
tot4+=num4;
tot5+=num5;
//You write the code that updates the number of each food item that
//has been sold so far today by using the number of each food item
//that was ordered by a customer


return;
}

void summary(int tot1, int tot2, int tot3, int tot4, int tot5, int customers);
{

const double price1 = 6.95,
price2 = 5.75,
price3 = 7.25,
price4 = 8.95,
price5 = 4.95;

double sale1, //sale amount of Buffalo Wings for the day
sale2, //sale amount of Super Burgers for the day
sale3, //sale of Italian Sandwiches for the day
sale4, //sale of Shrimp Nuggets for the day
sale5, //sale of Veggie Supremes for the day
totsales;//total sales for the day

sale1 = tot1*price1;
sale2 = tot2*price2;
sale3 = tot3*price3;
sale4 = tot4*price4;
sale5 = tot5*price5;

totsales = sale1+sale2+sale3+sale4+sale5;

oracleguy
05-05-2009, 06:23 AM
The function prototypes need to be moved outside of the main function, place them before the main function.

Where exactly is the undeclared errors occurring?

lvpnk
05-05-2009, 03:14 PM
Ok, I will do that.

The undeclared is happening after "void compute_totals" where it says tot1, tot2, tot3, tot4, tot5 near the bottom of the code.

lvpnk
05-05-2009, 03:51 PM
Ok, I've been working the code out and now I get that the variables tot1, tot2, etc are undeclared at the top in the do while statement at the compute_totals when I call the function which is located right before "while(another());" at the beginning of the code.

#include<iostream>
#include<fstream>
#include<iomanip>
#include<cctype>
#include<cstdlib>
#include"another.cpp"

using namespace std;

ofstream outs; //Declare outs globally so that you can access it in the
//functions directly




int main()
{


int num1, //number of Buffalo Wings ordered by a single customer
num2, //number of Super Burgers ordered by a single customer
num3, //number of Italian Sandwiches ordered by a single customer
num4, //number of Shrimp Nuggets ordered by a single customer
num5, //number of Veggie Supremes ordered by a single customer
customers; //number of customers
int total1, //total number of Buffalo Wings ordered for the day
total2, //total number of Super Burgers ordered for the day
total3, //total number of Italian Sandwiches ordered for the day
total4, //total number of Shrimp Nuggets ordered for the day
total5; //total number of Veggie Supremes ordered for the day


//Function Prototypes

void describe_program();
void display_menu();
void get_order(int& num1,int& num2,int& num3, int& num4, int& num5);
void compute_display_bill(int num1, int num2, int num3, int num4, int num5);
void compute_totals(int num1, int num2, int num3, int num4, int num5,
int& tot1, int& tot2, int& tot3, int& tot4, int& tot5);
bool another();
void summary(int tot1,int tot2,int tot3,int tot4,int tot5,int customers);



//open external file
outs.open("food_court.txt",ios::app);

describe_program();

//Initialize variables

total1 = 0, total2 = 0, total3 = 0, total4 = 0, total5 = 0, customers = 0;

do //processing of a customer
{
customers++;
//update customer count
display_menu();
//display the menu
get_order(num1,num2,num3, num4,num5);
//get order from the customer
compute_display_bill(num1, num2,num3, num4, num5);
//Indicate the customer number at external file
compute_totals(num1,num2,num3,num4, num5, tot1, tot2, tot3, tot4, tot5);
//compute and display the customer's bill at the screen and external file

//compute totals so far
}while(another()); //while there is another customer
//print a daily summary at the screen and external file
summary (tot1, tot2, tot3, tot4, tot5,customers);


outs.close();
system("PAUSE");
return 0;
}


//Define functions here

//You write the code! It's similar to the function again()


void describe_program()
{

cout<<"This program will ask you to place an order at a fast food restaurant.\n"
<<"There are 5 items on the menu including buffalo wings, a Super burger,\n"
<<"an Italian sandwich, shrimp nuggets and a veggie supreme. You will\n"
<<"enter your choice according to the corresponding order numbers on each\n"
<<"item. You may order as many items as you like. When the days orders\n"
<<"are complete, enter 0 and the program will calculate the total amount\n"
<<"of money, items, amount each item cost and the total number of \n"
<<"customers for that day. All of this information will be shown at the \n"
<<"screen and sent to the external file food_court.txt.\n\n";
//You write the code

return;
}

void display_menu()
{
cout<<"Welcome to the best restaurant! Please have a look at our menu and make\n"
<<"your choice.\n"
<<"1 - Buffalo Wings - $6.95\n"
<<"2 - Super Burger - $5.75\n"
<<"3 - Italian Sandwich - $7.25\n"
<<"4 - Shrimp Nuggets - $8.95\n"
<<"5 - Veggie Supreme - $4.95\n";

//Display menu of items and get order
//You write the code
return;
}


void get_order(int& num1,int& num2,int& num3, int& num4, int& num5)
{
const int Sentinel = 0;
int choice, //menu choice made by customer
num; //number of a particular food item ordered by a customer
cout<<"Which item would like like? Please enter the item number:";
cin>>choice;

//Initialize num1, num2 etc. You write the code!
num1 = 0, num2 = 0, num3 = 0, num4 = 0, num5 = 0;

while (choice!=Sentinel)
{
switch (choice)
{
case 1:
cout<<"How many of this item would you like? Please enter an amount:";
cin>>num;
num1+=num;
break;
case 2:
cout<<"How many of this item would you like? Please enter an amount:";
cin>>num;
num2+=num;
break;
case 3:
cout<<"How many of this item would you like? Please enter an amount:";
cin>>num;
num3+=num;
break;
case 4:
cout<<"How many of this item would you like? Please enter an amount:";
cin>>num;
num4+=num;
break;
case 5:
cout<<"How many of this item would you like? Please enter an amount:";
cin>>num;
num5+=num;
break;

default: cout<<"You have entered an invalid menu item! Please enter a valid\n"
<<"number\n";
}
cout<<"Please enter an item number or 0 to complete your order:";
cin>>choice;
//Process customer order. Use a while loop with a senatinel value of 0.
//Use a switch statement to ask how many of the selection the customer
//wants and update the number of that food item by the number ordered by the
//customer
//You write the code!
}
return;
}



void compute_display_bill(int num1, int num2, int num3, int num4, int num5)
{


const double price1 = 6.95, //price of Buffalo Wings
price2 = 5.75, //price of Super Burgers
price3 = 7.25, //price of Italian Sandwich
price4 = 8.95, //price of Shrimp Nuggets
price5 = 4.95; //price of Veggie Supreme

double cost1, //cost of num1 Buffalo Wings
cost2, //cost of num2 Super Burgers
cost3, //cost of num3 Italian Sandwiches
cost4, //cost of num4 Shrimp Nuggets
cost5, //cost of num5 Veggie Supremes
totcost; //total cost of the order


cost1 = num1*price1;

cost2 = num2*price2;

cost3 = num3*price3;

cost4 = num4*price4;

cost5 = num5*price5;

totcost = cost1+cost2+cost3+cost4+cost5;

cout<<"The total cost for this order is "<<totcost<<".\n";

//You write the code that computes the above costs and displays them
//at the screen and the external file!
return;
}

void compute_totals(int num1,int num2,int num3,int num4,int num5,
int& tot1,int& tot2,int& tot3,int& tot4,int& tot5)
{
tot1+=num1;
tot2+=num2;
tot3+=num3;
tot4+=num4;
tot5+=num5;
//You write the code that updates the number of each food item that
//has been sold so far today by using the number of each food item
//that was ordered by a customer


return;
}

void summary(int tot1,int tot2,int tot3,int tot4,int tot5,int customers)
{

const double price1 = 6.95,
price2 = 5.75,
price3 = 7.25,
price4 = 8.95,
price5 = 4.95;

double sale1, //sale amount of Buffalo Wings for the day
sale2, //sale amount of Super Burgers for the day
sale3, //sale of Italian Sandwiches for the day
sale4, //sale of Shrimp Nuggets for the day
sale5, //sale of Veggie Supremes for the day
totsales;//total sales for the day

sale1 = tot1*price1;
sale2 = tot2*price2;
sale3 = tot3*price3;
sale4 = tot4*price4;
sale5 = tot5*price5;

totsales = sale1+sale2+sale3+sale4+sale5;

oracleguy
05-05-2009, 04:10 PM
Well you declare them as total1, total2, etc. why are you then referring to them as to1, tot2, tot3, etc.?

lvpnk
05-05-2009, 04:26 PM
I figured out what was wrong, I didn't declare tot as well as total, they are 2 different variables. and I also needed to initialize tot at 0 as well. Thanks for the help.