EMERGENCY!Well guys, I'm faily new to programming and I'm having a problem with one of my codes. Its basically an online pizza ordering system. I can get it to run but I just cant get it to calculate the price at the end. Anybody please help me and with haste T_T. I need to submit it by tomorrow T__T. Feel like crying~
}
void terms_and_conditions ( )
{
cout<<"1.Domino's pricing is all inclusive. We do not add any extra charges for delivery. So what you see is what you pay.No surprises!\n";
cout<<"2.Domino's is the only pizza company that guarantees your order will arrive within 30 minutes or we’ll give you a free Regular Pizza voucher!\n";
cout<<"3.Domino's guarantees satisfaction! Your pizza is guaranteed to be hot,fresh and great tasting when it arrives at your doorstep,otherwise we’ll replace your order or refund your money.\n";
cout<<"4.Any customer that spends more than RM 100 per order here at Domino's shall be given one large pizza for FREE!\n\n";
}
void menu ( )
{
char crust;
char size;
cout<<"What size would you like?\n";
cout<<"'S' Small, 'M' Medium, 'L' Large\n";
cin>>size;
cout<<"What type of crust would you like?\n";
cout<<"'P' Pan, 'H' Hand Tossed, 'D' Deep Dish\n";
cin>>crust;
int pizza_number;
cout<<"What type of pizza would you like to purchase?"<<endl;
cout<<"1. Beef Pepperoni\n";
cout<<"2. Chicken Pepperoni\n";
cout<<"3. Spicy Sambal\n";
cout<<"4. Seafood Delight\n";
cout<<"5. Extravaganzza\n";
cin>>pizza_number;
{
if (pizza_number==1)
cout<<"You have chosen to order the Beef Pepperoni pizza.\n\n";
else if(pizza_number==2)
cout<<"You have chosen to order the Chicken Pepperoni pizza.\n\n";
else if (pizza_number==3)
cout<<"You have chosen to order the Spicy Sambal pizza.\n\n";
else if (pizza_number==4)
cout<<"You have chosen to order the Seafood Delight pizza.\n\n";
else if (pizza_number==5)
cout<<"You have chosen to order the Extravaganzza pizza.\n\n";
cout<<"How many of this particular pizza would you like to order?\n";
cin>>num;
cout<<"The number of this particular pizza you have ordered is: "<<num<<endl;
cout<<"\n\n";
}
double calCost( )
{
double costOfPizza;
double totalCost;
const int PanCrustSm=10;
const int PanCrustMd=20;
const int PanCrustLg=30;
const int DeepCrustSm=9;
const int DeepCrustMd=18;
const int DeepCrustLg=27;
const int HandTossSm=8;
const int HandTossMd=16;
const int HandTossLg=25;
This compiles but I don't think it is the right way to do what you want though. You should try and encapsulate most of this in a class and use methods of that class to do what you are trying to do.
However... a few pointers:
You either need to fully qualify the classes you are using or declare that you are using a particular namespace as most of the problems were down to that.
Your other errors were becuase "sizeOfPizza" and "crust" were not declared and you never actually use an instance of the pizza struct anywhere (hence I added a variable of type "pizza" to your calculation method...
You should also try to use a switch statement to improve the flow in the calculation method...
But these are just my opinions. As I say, the below will now compile though...
#include <iostream>
#include <math.h>
// added this...
usingnamespace std;
void menu();
void terms_and_conditions ( );
void exit();
struct pizza
{
char crust;
char size;
};
int main ()
{
int option;
do
{
cout<<"Welcome to Josh's Pizza Online Ordering Service\n";
cout<<"----------------\n\n";
cout<<"1. Menu\n";
cout<<"2. Terms and Conditions\n";
cout<<"3. Exit\n\n";
cout<<"----------------\n\n";
cout<<"Enter option: ";
cin>>option;
switch(option)
{
case 1: menu ( );
break;
case 2: terms_and_conditions ( );
break;
case 3: exit ( );
break;
default: cout<<"Sorry invalid option entered. Please try again"<<endl;
}
}while (option!=3);
}
void terms_and_conditions ( )
{
cout<<"1.Domino's pricing is all inclusive. We do not add any extra charges for delivery. So what you see is what you pay.No surprises!\n";
cout<<"2.Domino's is the only pizza company that guarantees your order will arrive within 30 minutes or we’ll give you a free Regular Pizza voucher!\n";
cout<<"3.Domino's guarantees satisfaction! Your pizza is guaranteed to be hot,fresh and great tasting when it arrives at your doorstep,otherwise we’ll replace your order or refund your money.\n";
cout<<"4.Any customer that spends more than RM 100 per order here at Domino's shall be given one large pizza for FREE!\n\n";
}
void menu ( )
{
char crust;
char size;
cout<<"What size would you like?\n";
cout<<"'S' Small, 'M' Medium, 'L' Large\n";
cin>>size;
cout<<"What type of crust would you like?\n";
cout<<"'P' Pan, 'H' Hand Tossed, 'D' Deep Dish\n";
cin>>crust;
int pizza_number;
cout<<"What type of pizza would you like to purchase?"<<endl;
cout<<"1. Beef Pepperoni\n";
cout<<"2. Chicken Pepperoni\n";
cout<<"3. Spicy Sambal\n";
cout<<"4. Seafood Delight\n";
cout<<"5. Extravaganzza\n";
cin>>pizza_number;
{
if (pizza_number==1)
cout<<"You have chosen to order the Beef Pepperoni pizza.\n\n";
elseif(pizza_number==2)
cout<<"You have chosen to order the Chicken Pepperoni pizza.\n\n";
elseif (pizza_number==3)
cout<<"You have chosen to order the Spicy Sambal pizza.\n\n";
elseif (pizza_number==4)
cout<<"You have chosen to order the Seafood Delight pizza.\n\n";
elseif (pizza_number==5)
cout<<"You have chosen to order the Extravaganzza pizza.\n\n";
else
cout<<"Invalid selection entered. Please try again.\n\n";
}
int num;
cout<<"How many of this particular pizza would you like to order?\n";
cin>>num;
cout<<"The number of this particular pizza you have ordered is: "<<num<<endl;
cout<<"\n\n";
}
double calCost(pizza p)
{
double costOfPizza;
double totalCost;
constint PanCrustSm=10;
constint PanCrustMd=20;
constint PanCrustLg=30;
constint DeepCrustSm=9;
constint DeepCrustMd=18;
constint DeepCrustLg=27;
constint HandTossSm=8;
constint HandTossMd=16;
constint HandTossLg=25;
if(p.size=='S' && p.crust =='P')
costOfPizza = PanCrustSm;
if(p.size=='M' && p.crust=='P')
costOfPizza = PanCrustMd;
if(p.size=='L' && p.crust =='P')
costOfPizza = PanCrustLg;
if(p.size=='S' && p.crust=='H')
costOfPizza = HandTossSm;
if(p.size=='M' && p.crust=='H')
costOfPizza = HandTossMd;
if(p.size=='L' && p.crust=='H')
costOfPizza = HandTossLg;
if(p.size=='S' && p.crust=='D')
costOfPizza= DeepCrustSm;
if(p.size=='M' && p.crust=='D')
costOfPizza= DeepCrustMd;
if(p.size=='L' && p.crust=='D')
costOfPizza= DeepCrustLg;
totalCost=costOfPizza;
return totalCost;
}
void exit ( )
{
cout<<"Thank you for choosing Domino's Pizza. Have a nice day :D.\n";
}
Hey Phil. Thanks so much for the speedy reply. The program now compiles like you say! But once I enter the menu and I reach up to the point where I decide how many of a certain pizza I want, it still doesn't perform any form of calculation D:
what makes you think itll perform any calculations when you never use the CalCost function :P..
you need to create a pizza struct in the menu, set its crust and size, and pass it to the CalCost function, wich will return the cost of one pizza.
then you cout << numberofpizzas * CalCost(yourpizza)
Oh I see! I`ve been at this for hours. I haven't taken dinner or slept and its 3am here. I just wanna get this done so all help is VERY VERY much appreciated thank you :)
Here is an example of a pizza class... remember that you need an instance of your class before you can use it. Try putting the control methods in a similar class... you will gain extra credits!
Remember that this may not be perfect - as I only just quickly knocked it up but it is a better design pattern that what you were using. I hope this helps.
Yea this does seem much easier. But can someone just help me with the calculation bit. Like actually show me how its done based on my coding? I WOULD REALLLLLY APPRECIATE IT. T___T
#include <iostream>
#include <math.h>
// added this...
usingnamespace std;
void menu();
void terms_and_conditions ( );
void exit();
struct pizza
{
char crust;
char size;
};
double CalCost(pizza);
int main ()
{
int option;
do
{
cout<<"Welcome to Josh's Pizza Online Ordering Service\n";
cout<<"----------------\n\n";
cout<<"1. Menu\n";
cout<<"2. Terms and Conditions\n";
cout<<"3. Exit\n\n";
cout<<"----------------\n\n";
cout<<"Enter option: ";
cin>>option;
switch(option)
{
case 1: menu ( );
break;
case 2: terms_and_conditions ( );
break;
case 3: exit ( );
break;
default: cout<<"Sorry invalid option entered. Please try again"<<endl;
}
}while (option!=3);
}
void terms_and_conditions ( )
{
cout<<"1.Domino's pricing is all inclusive. We do not add any extra charges for delivery. So what you see is what you pay.No surprises!\n";
cout<<"2.Domino's is the only pizza company that guarantees your order will arrive within 30 minutes or we’ll give you a free Regular Pizza voucher!\n";
cout<<"3.Domino's guarantees satisfaction! Your pizza is guaranteed to be hot,fresh and great tasting when it arrives at your doorstep,otherwise we’ll replace your order or refund your money.\n";
cout<<"4.Any customer that spends more than RM 100 per order here at Domino's shall be given one large pizza for FREE!\n\n";
}
void menu ( )
{
pizza p;//<----
cout<<"What size would you like?\n";
cout<<"'S' Small, 'M' Medium, 'L' Large\n";
cin>>p.size;//<----
cout<<"What type of crust would you like?\n";
cout<<"'P' Pan, 'H' Hand Tossed, 'D' Deep Dish\n";
cin>>p.crust;//<----
int pizza_number;
cout<<"What type of pizza would you like to purchase?"<<endl;
cout<<"1. Beef Pepperoni\n";
cout<<"2. Chicken Pepperoni\n";
cout<<"3. Spicy Sambal\n";
cout<<"4. Seafood Delight\n";
cout<<"5. Extravaganzza\n";
cin>>pizza_number;
{
if (pizza_number==1)
cout<<"You have chosen to order the Beef Pepperoni pizza.\n\n";
elseif(pizza_number==2)
cout<<"You have chosen to order the Chicken Pepperoni pizza.\n\n";
elseif (pizza_number==3)
cout<<"You have chosen to order the Spicy Sambal pizza.\n\n";
elseif (pizza_number==4)
cout<<"You have chosen to order the Seafood Delight pizza.\n\n";
elseif (pizza_number==5)
cout<<"You have chosen to order the Extravaganzza pizza.\n\n";
else
cout<<"Invalid selection entered. Please try again.\n\n";
}
int num;
cout<<"How many of this particular pizza would you like to order?\n";
cin>>num;
cout<<"The number of this particular pizza you have ordered is: "<<num<<endl;
cout<<"Cost : " << calCost(p)*num << endl;//<---
cout<<"\n\n";
}
double calCost(pizza p)
{
double costOfPizza;
double totalCost;
constint PanCrustSm=10;
constint PanCrustMd=20;
constint PanCrustLg=30;
constint DeepCrustSm=9;
constint DeepCrustMd=18;
constint DeepCrustLg=27;
constint HandTossSm=8;
constint HandTossMd=16;
constint HandTossLg=25;
if(p.size=='S' && p.crust =='P')
costOfPizza = PanCrustSm;
if(p.size=='M' && p.crust=='P')
costOfPizza = PanCrustMd;
if(p.size=='L' && p.crust =='P')
costOfPizza = PanCrustLg;
if(p.size=='S' && p.crust=='H')
costOfPizza = HandTossSm;
if(p.size=='M' && p.crust=='H')
costOfPizza = HandTossMd;
if(p.size=='L' && p.crust=='H')
costOfPizza = HandTossLg;
if(p.size=='S' && p.crust=='D')
costOfPizza= DeepCrustSm;
if(p.size=='M' && p.crust=='D')
costOfPizza= DeepCrustMd;
if(p.size=='L' && p.crust=='D')
costOfPizza= DeepCrustLg;
totalCost=costOfPizza;
return totalCost;
}
void exit ( )
{
cout<<"Thank you for choosing Domino's Pizza. Have a nice day :D.\n";
}
Hey thanks guys for all your help. The calculation works but the numbers come out mixed with words. Anyway my teacher said she'll help me debug my program so I think I`ll just take it over to her. Thanks so much guys for all your help = )