help with pizza program

im having trouble getting my pizza program to work.
its suppose to ask user for type of pizza/size of pizza. amount of toppings..
suppose to use a class/set/get. and print out the total cost.

this is what i got so far.
main problem im having is that it wont read custCrust in calcCost()

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
#include <iostream>
using namespace std;

class Jimmy
{
public:
char custCrust;      // stores P,D or H to indicate pan, deep dish or hand tossed crust           
char custSize;          // stores S, M or L to indicate small, medium or large pizza
int pepperoni;      // stores number of pepperoni toppings for this pizza            
int onlonPepper;     // stores number of onion& pepper toppings for this pizza
//bool cheese;        // indicates if there is cheese on this pizza, default is True
int totalTop;

void setCrust(char ctype);
void setSize(char size);
//void setCheese();
void setPepperoni(int quantity);
void setOP(int quantity);
const char getCrust();
const char getSize( );
void resetToppings();
//void noCh();
const double calcCost( );
const int totalToppings();     // note that this function is Private
//const void printToppings(ostream& out);  // prints toppings only
//const void printPizzaStats(ostream& out); // prints crust, size, cheese, toppings

};

int main()
{
    Jimmy custPizza;
	char custPep;
	char custOnAnPepr;
	
	cout << "Welcome to Jimmy's Pizza.\n";
	cout << "What type of crust would you like?\n"
		 << "'P' pan, 'D' deep dish, 'H' hand tossed.\n";
	cin >> custPizza.custCrust;
	
	cout << "What size would you like?\n"
		 << "'S' small, 'M' medium, 'L' large.\n";
	cin >> custPizza.custSize;

	cout << "Would you like pepperoni? (y/n) \n";
	cin >> custPep;
	if (custPep == 'y' || custPep == 'Y')
		cout << "How much pepperoni would you like?\n";
		cin >> custPizza.pepperoni;

	cout << "Would you like onions peppers? (y/n) \n";
	cin >> custOnAnPepr;
	if (custOnAnPepr == 'y' || custOnAnPepr == 'Y')
		cout << "How much onions and peppers would you like?\n";
		cin >> custPizza.onlonPepper;


	int fake;
	cout << "the total cost of your pizza is \n";
	custPizza.calcCost();
	cin >> fake;
}

const double Jimmy::calcCost()
{

const int PanCrustSm = 5;
const int PanCrustMd = 8;
const int PanCrustLg = 10;
const int DeepCrustsm = 6;
const int DeepCrustMd = 9;
const int DeepCrustLg = 11;
const int HandTosSm = 7;
const int HandTosMd = 10;
const int HandTosLg = 12;
const int toppings = 2;
double costOfPizza;
double totalCost;
int costOfTop;


	if custCrust == 'P' && sizeOfCrust == 'S'
		costOfPizza = PanCrustSm;
	if custCrust == 'P' && sizeOfCrust == 'M'
		costOfPizza = PanCrustMd;
	if custCrust == 'P' && sizeOfCrust == 'L'
		costOfPizza = PanCrustLg;
	if custCrust == 'D' && sizeOfCrust == 'S'
		costOfPizza = DeepCrustSm;
	if custCrust == 'D' && sizeOfCrust == 'M'
		costOfPizza = DeepCrustMd;
	if custCrust == 'D' && sizeOfCrust == 'L'
		costOfPizza = DeepCrustLg;
	if custCrust == 'H' && sizeOfCrust == 'S'
		costOfPizza = HandCrustSm;
	if custCrust == 'H' && sizeOfCrust == 'M'
		costOfPizza = HandTosCrustMd;
	if custCrust == 'H' && sizeOfCrust == 'L'
		costOfPizza = HandTosCrustLg;
	
	costOfTop = totalTop * toppings; // the cost of all toppings
	totalCost = costOfPizza + costOfTop;
	
	return totalCost;
}

const int Jimmy::totalToppings()
{
	totalTop = pepperoni + onlonPepper;
	return totalTop;
}

void Jimmy::setCrust(char ctype)
{
	custCrust = ctype;
}

const char Jimmy::getCrust()
{
	return custCrust;
}

void Jimmy::setSize(char size)
{
	custSize = size;
}

const char Jimmy::getSize()
{
	return custSize;
}

void Jimmy::setPepperoni(int quantity)
{
	pepperoni = quantity;
}

void Jimmy::setOP(int quantity)
{
	onlonPepper = quantity;
}

void Jimmy::resetToppings()
{
	pepperoni = 0;
	onlonPepper = 0;
}
Last edited on
Cito88,

First off, you get this program to actually compile? I wasn't able to, and I am using Dev C++ as my compiler. It doesn't compile for me because in this pizza program, there are many undeclared variables that you use in the code. There are also simple syntax errors, such as not putting parentheses around the argument to the if statements. Fixing these errors got this program to work fine. After fixing these errors, I found that the program did work, but did you finish it? It still needs some work as to it's actual functionality. If you fix it up, it will be just fine.

Here is the code that will compile, but still needs work to do what it's supposed to do.
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
#include <iostream>
using namespace std;

class Jimmy
{
public:
char custCrust;      // stores P,D or H to indicate pan, deep dish or hand tossed crust           
char custSize;          // stores S, M or L to indicate small, medium or large pizza
int pepperoni;      // stores number of pepperoni toppings for this pizza            
int onlonPepper;     // stores number of onion& pepper toppings for this pizza
//bool cheese;        // indicates if there is cheese on this pizza, default is True
int totalTop;

void setCrust(char ctype);
void setSize(char size);
//void setCheese();
void setPepperoni(int quantity);
void setOP(int quantity);
const char getCrust();
const char getSize( );
void resetToppings();
//void noCh();
const double calcCost( );
const int totalToppings();     // note that this function is Private
//const void printToppings(ostream& out);  // prints toppings only
//const void printPizzaStats(ostream& out); // prints crust, size, cheese, toppings

};

int main()
{
    Jimmy custPizza;
	char custPep;
	char custOnAnPepr;
	
	cout << "Welcome to Jimmy's Pizza.\n";
	cout << "What type of crust would you like?\n"
		 << "'P' pan, 'D' deep dish, 'H' hand tossed.\n";
	cin >> custPizza.custCrust;
	
	cout << "What size would you like?\n"
		 << "'S' small, 'M' medium, 'L' large.\n";
	cin >> custPizza.custSize;

	cout << "Would you like pepperoni? (y/n) \n";
	cin >> custPep;
	if (custPep == 'y' || custPep == 'Y')
		cout << "How much pepperoni would you like?\n";
		cin >> custPizza.pepperoni;

	cout << "Would you like onions peppers? (y/n) \n";
	cin >> custOnAnPepr;
	if (custOnAnPepr == 'y' || custOnAnPepr == 'Y')
		cout << "How much onions and peppers would you like?\n";
		cin >> custPizza.onlonPepper;


	int fake;
	cout << "the total cost of your pizza is \n";
	custPizza.calcCost();
	cin >> fake;
}

const double Jimmy::calcCost()
{

const int PanCrustSm = 5;
const int PanCrustMd = 8;
const int PanCrustLg = 10;
const int DeepCrustsm = 6;
const int DeepCrustMd = 9;
const int DeepCrustLg = 11;
const int HandTosSm = 7;
const int HandTosMd = 10;
const int HandTosLg = 12;
const int toppings = 2;
double costOfPizza;
double totalCost;
int costOfTop;


	if (custCrust == 'P' && custSize == 'S')
		costOfPizza = PanCrustSm;
	if (custCrust == 'P' && custSize == 'M')
		costOfPizza = PanCrustMd;
	if (custCrust == 'P' && custSize == 'L')
		costOfPizza = PanCrustLg;
	if (custCrust == 'D' && custSize == 'S')
		costOfPizza = DeepCrustsm;
	if (custCrust == 'D' && custSize == 'M')
		costOfPizza = DeepCrustMd;
	if (custCrust == 'D' && custSize == 'L')
		costOfPizza = DeepCrustLg;
	if (custCrust == 'H' && custSize == 'S')
		costOfPizza = HandTosSm;
	if (custCrust == 'H' && custSize== 'M')
		costOfPizza = HandTosMd;
	if (custCrust == 'H' && custSize == 'L')
		costOfPizza = HandTosLg;
	
	costOfTop = totalTop * toppings; // the cost of all toppings
	totalCost = costOfPizza + costOfTop;
	
	return totalCost;
}

const int Jimmy::totalToppings()
{
	totalTop = pepperoni + onlonPepper;
	return totalTop;
}

void Jimmy::setCrust(char ctype)
{
	custCrust = ctype;
}

const char Jimmy::getCrust()
{
	return custCrust;
}

void Jimmy::setSize(char size)
{
	custSize = size;
}

const char Jimmy::getSize()
{
	return custSize;
}

void Jimmy::setPepperoni(int quantity)
{
	pepperoni = quantity;
}

void Jimmy::setOP(int quantity)
{
	onlonPepper = quantity;
}

void Jimmy::resetToppings()
{
	pepperoni = 0;
	onlonPepper = 0;
}
Last edited on
Topic archived. No new replies allowed.