Display an order from a nested while loop

Hi all,
Name's Liz, and this is my first post. I've been searching the forums and can't find a thread that answers my question, and I'm kind of stumped.

This is my second program for my CS class, so please bear with me and my lack of experience. I need to design a program that has the following requirements:

"In this assignment you are to write an application for a pizza parlor. The application will allow the user to order 1 or 2 pizzas with 1 or 2 ingredients. The pizzas come in [S]mall, [M]edium, and [L]arge sizes and the list of ingredients include [S]ausage, [P]epperoni, [M]ushroom, [O]nion, [G]reen pepper, [B]lack olive, and [C]anadian bacon.

The costs for the basic pies are $8.95, $9.95 and $10.95 respectively, with each ingredient adding an extra $1.15. Display the order back to them, along with the cost. "

So, if a user ordered two pizzas, one small with pepperoni, and one large with mushroom/black olive, to display the order, it should appear like this:

"Ordered: 1 S (P)
1 L (M, B)
Total cost: $23.35"


I'm having no trouble with the total cost, but I am stumped on how to display the order back to the user because I'm using while loops. Here's my code, and it's messy as heck:
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
#include <iostream>
using namespace std;

int main()
{
	int numPizzas, numIngred;
	double costSize, total1, total2;
	char pizzaSize, ingredType, orderedIng, orderedSize;
	const double smallPizza = 8.95, medPizza = 9.95, largePizza = 10.95, ingredCost = 1.15;

//Loop for pizzas
cout << "Enter number of pizzas [1-2]: ";
cin >> numPizzas;
	
		int count = 1;
		int pizzaCount = numPizzas;

	while ((pizzaCount >= 1)&&(pizzaCount <= 2))
	{

		cout << endl << "Pizza #" << count << ": " << endl
			 << "[S]mall, [M]edium, [L]arge: ";
		cin >> pizzaSize;
		count++;
		pizzaCount--;

			switch (pizzaSize)
			{
				case 'S':
				case 's':
					costSize = smallPizza;
					orderedSize = pizzaSize;
					break;
				case 'M':
				case 'm':
					costSize = medPizza;
					orderedSize = pizzaSize;
					break;
				case 'L':
				case 'l':
					costSize = largePizza;
					orderedSize = pizzaSize;
					break;
				default:
					cout << "Please enter a valid pizza size." << endl << endl;
					return 0;
			}
		total1 = (numPizzas*costSize);

		cout << "    # of ingredients [1-2]: ";
		cin >> numIngred;

		int count2 = 1;
		int ingredCount = numIngred;

			//Nested loop for ingredients
			//I'm trying to figure out what action I should take after each case. Tried setting up another variable,
			//orderedIng, so I could display the order...Stumped.
			while ((ingredCount >= 1)&&(ingredCount <= 2))
			{ 
				cout << "   #" << count2 << "[S, P, M, O, G, B, C]: ";
				cin >> ingredType;
				count2 ++;
				ingredCount--;

					switch (ingredType)
					{
						case 'S':
						case 's':
							orderedIng = 'S';
							break;
						case 'P':
						case 'p':
							orderedIng = 'P';
							break;
						case 'M':
						case 'm':
							orderedIng = 'M';
							break;
						case 'O':
						case 'o':
							orderedIng = 'O';
							break;
						case 'G':
						case 'g':
							orderedIng = 'G';
							break;
						case 'B':
						case 'b':
							orderedIng = 'B';
							break;
						case 'C':
						case 'c':
							orderedIng = 'C';
							break;
						default:
							cout << "Please enter a valid ingredient." << endl << endl;
							return 0;
					}
			total2 = (total1 + (numIngred*ingredCost*numPizzas));
			}
	}
//Here is where I need to display the order and the cost back to the user.
//cout.setf(ios::fixed);
//cout.setf(ios::showpoint);
//cout.precision(2);
//cout << endl << endl << "Ordered: 1 " << pizzaSize << " (" << ingredType << orderedIng << ")" << endl;
//                     << "Total cost: $" << total2 << endl << endl;
return 0;
}



Okay, so I fiddled around with it, and I've altered the part with the ingredients. I don't have the end quite finished, but I'm trying to figure out what to do with my char variables here.

Visual Studio won't let me run my program without first initializing my char variables, orderedIng1 and orderedIng2. Why? And then when I reassign them and output them, they still come up as the initialized values (which are blank spaces). Any tips? Please help.

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

int main()
{
	int numPizzas, numIngred;
	double costSize, total1, total2;
	char pizzaSize, ingredType, orderedSize, orderedIng1 = ' ', orderedIng2 = ' ';
	const double smallPizza = 8.95, medPizza = 9.95, largePizza = 10.95, ingredCost = 1.15;

//Loop for pizzas
cout << "Enter number of pizzas [1-2]: ";
cin >> numPizzas;
	
		int count = 1;
		int pizzaCount = numPizzas;

	while ((pizzaCount >= 1)&&(pizzaCount <= 2))
	{

		cout << endl << "Pizza #" << count << ": " << endl
			 << "[S]mall, [M]edium, [L]arge: ";
		cin >> pizzaSize;
		count++;
		pizzaCount--;

			switch (pizzaSize)
			{
				case 'S':
				case 's':
					costSize = smallPizza;
					orderedSize = pizzaSize;
					break;
				case 'M':
				case 'm':
					costSize = medPizza;
					orderedSize = pizzaSize;
					break;
				case 'L':
				case 'l':
					costSize = largePizza;
					orderedSize = pizzaSize;
					break;
				default:
					cout << "Please enter a valid pizza size." << endl << endl;
					return 0;
			}
		total1 = (numPizzas*costSize);

		cout << "    # of ingredients [1-2]: ";
		cin >> numIngred;
		
		int count2 = 1;
		int ingredCount = numIngred;

			//Nested loop for ingredients
			//I'm trying to figure out what action I should take after each case. Tried setting up another variable,
			//orderedIng, so I could display the order...Stumped.
			while ((ingredCount >= 1)&&(ingredCount <= 2))
			{ 
				
				cout << "   #" << count2 << "[S, P, M, O, G, B, C]: ";
				cin >> ingredType;
				count2 ++;
				ingredCount--;
			
				if (ingredCount == 1)
				{
				
					switch (ingredType)
					{
						case 'S':
						case 's':
							orderedIng1 = 'S';
							break;
						case 'P':
						case 'p':
							orderedIng1 = 'P';
							break;
						case 'M':
						case 'm':
							orderedIng1 = 'M';
							break;
						case 'O':
						case 'o':
							orderedIng1 = 'O';
							break;
						case 'G':
						case 'g':
							orderedIng1 = 'G';
							break;
						case 'B':
						case 'b':
							orderedIng1 = 'B';
							break;
						case 'C':
						case 'c':
							orderedIng1 = 'C';
							break;
						default:
							cout << "Please enter a valid ingredient." << endl << endl;
							return 0;
					}
				}
				else if (ingredCount == 2)
				{

					switch (ingredType)
					{
						case 'S':
						case 's':
							orderedIng2 = 'S';
							break;
						case 'P':
						case 'p':
							orderedIng2 = 'P';
							break;
						case 'M':
						case 'm':
							orderedIng2 = 'M';
							break;
						case 'O':
						case 'o':
							orderedIng2 = 'O';
							break;
						case 'G':
						case 'g':
							orderedIng2 = 'G';
							break;
						case 'B':
						case 'b':
							orderedIng2 = 'B';
							break;
						case 'C':
						case 'c':
							orderedIng2 = 'C';
							break;
						default:
							cout << "Please enter a valid ingredient." << endl << endl;
							return 0;
					}
				}
			
			total2 = (total1 + (numIngred*ingredCost*numPizzas));
			}
	}

//Here is where I need to display the order and the cost back to the user.
cout.setf(ios::fixed);
cout.setf(ios::showpoint);
cout.precision(2);
cout << endl << endl << "Ordered: 1 " << pizzaSize << " (" << orderedIng1 << ", " << orderedIng2 << ")" << endl
                     << "Total cost: $" << total2 << endl << endl;
return 0;
}

Topic archived. No new replies allowed.