Assistance needed T_T

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~

#include <iostream.h>
#include <math.h>

void menu();
void terms_and_conditions ( );
void exit();
struct pizza
{
char crust;
char size;

};
void 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";


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";

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( )
{
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;

if(sizeOfPizza=='S' && crust =='P')
costOfPizza = PanCrustSm;

if(sizeOfPizza=='M' && crust=='P')
costOfPizza = PanCrustMd;

if(sizeOfPizza=='L' && crust =='P')
costOfPizza = PanCrustLg;

if(sizeOfPizza=='S' && crust=='H')
costOfPizza = HandTossSm;

if(sizeOfPizza=='M' && crust=='H')
costOfPizza = HandTossMd;

if(sizeOfPizza=='L' && crust=='H')
costOfPizza = HandTossLg;

if(sizeOfPizza=='S' && crust=='D')
costOfPizza= DeepCrustSm;

if(sizeOfPizza=='M' && crust=='D')
costOfPizza= DeepCrustMd;

if(sizeOfPizza=='L' && crust=='D')
costOfPizza= DeepCrustLg;

totalCost=costOfPizza;

return totalCost;

}

void exit ( )
{
cout<<"Thank you for choosing Domino's Pizza. Have a nice day :D.\n";
}
Last edited on
Here you go....

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...

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172

#include <iostream>
#include <math.h>

// added this...
using namespace 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"; 
		
		
		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";
		
		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;
	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;
	
	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";
}


Regards,

Phil.
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)
Last edited on
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!

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
class Pizza
{
	public:
		Pizza();
		Pizza(const Pizza& value);
		virtual ~Pizza();
		
		Pizza& operator=(const Pizza& rhs);
		
		void SetCrust(char value) {m_crust = value;}
		char GetCrust() const {return m_crust;}
		
		void SetSize(char value) {m_size = value;}
		char GetSize() const {return m_size;}
		
		double CalculateCost() const;
		
	private:
		char m_crust;
		char m_size;
		
		const static int PanCrustSm=10;
		const static int PanCrustMd=20;
		const static int PanCrustLg=30;
		
		const static int DeepCrustSm=9;
		const static int DeepCrustMd=18;
		const static int DeepCrustLg=27;
		
		const static int HandTossSm=8;
		const static int HandTossMd=16;
		const static int HandTossLg=25;
};

Pizza::Pizza():m_crust('D'),m_size('S') {};
Pizza::Pizza(const Pizza& value):m_crust(value.m_crust),m_size(value.m_size) {};
Pizza::~Pizza() {m_crust = '\0'; m_size = '\0';}

Pizza& Pizza::operator=(const Pizza& rhs) 
{
	m_crust = rhs.m_crust; 
	m_size = rhs.m_size; 
	return *this;
}

double Pizza::CalculateCost() const
{	
	double costOfPizza = 0;
	
	switch(m_size)
	{
		case 'S':
		{
			if(m_crust == 'P')
				costOfPizza = PanCrustSm;
			if(m_crust == 'H')
				costOfPizza = HandTossSm;
			if(m_crust == 'D')
				costOfPizza= DeepCrustSm;
		}
		break;
		case 'M':
		{
			if(m_crust == 'P')
				costOfPizza = PanCrustMd;
			if(m_crust == 'H')
				costOfPizza = HandTossMd;
			if(m_crust == 'D')
				costOfPizza= DeepCrustMd;
		}
		break;
		case 'L':
		{
			if(m_crust == 'P')
				costOfPizza = PanCrustLg;
			if(m_crust == 'H')
				costOfPizza = HandTossLg;
			if(m_crust == 'D')
				costOfPizza= DeepCrustLg;
		}
		break;
		default:
		{
			// enter your default condition here...
		}	
		break;
	}
	return costOfPizza;
}


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.

Regards,

Phil.
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
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
#include <iostream>
#include <math.h>

// added this...
using namespace 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"; 
		
		
		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";
		
		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;
	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;
	
	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";
}
Last edited on
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 = )
Topic archived. No new replies allowed.