If statements

Hi all, I have a complicated question to ask you and I'm stuck on this.
What I'm trying to do in this project is to ask the user what kind of ingredients they want from this certain store that are in stock. After telling me the ingredient, I will then ask what sizes they want and keep each ingredients in their cart. In the end, I will have to total the whole thing together and list all the ingredients they have chosen and total price in the end.

Here's my first problem in this picture:
https://40.media.tumblr.com/147d99c8524add203262956a9b62a399/tumblr_nvsch82nS11qdp21xo1_1280.png

I can respond back to the user just fine with the milk part, but when I ask what size sugar they want and they say 8, the last line in this console window pops up too after they say 8. How can I remove this last line about the 10 oz?

Second problem in this picture:
https://40.media.tumblr.com/8cbf4da37672dd58398a162bc2328e0d/tumblr_nvscmtkkOD1qdp21xo1_1280.png

When the user puts in 1, I can respond back by asking what size milk they want. However, if they were to pick something else like let's say...3 or 4, then nothing will pop up in the console window. How can I fix this?

Sorry about the confusion, but I have been stuck on this for awhile now. Thanks in advance.

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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
#include <iostream> 
#include <string>
#include <iomanip>
using namespace std;

int main()
{
	int ingredient1,
		ingredient2,
		ingredient3,
		ingredient4,
		ingredient5,
		ingredient6,
		ingredient7,
		ingredient8,
		ingredient9,
		ingredient11,
		ingredient22,
		ingredient33,
		ingredient44,
		ingredient55,
		ingredient66,
		ingredient77,
		ingredient88,
		ingredient99,
		a,
		b,
		c,
		d,
		e,
		f,
		g,
		h,
		i,
		q = 0,
		r = 0,
		s = 0,
		t = 0,
		u = 0,
		v = 0,
		x = 0,
		y = 0,
		z = 0;

	double milk,
		sugar,
		salt,
		lemonjuice,
		brownsugar,
		egg,
		frankshotsauce,
		chocolatemilk,
		vanillaextract;

	const double milk1 = 2.00,
		milk2 = 2.50,
		sugar1 = 1.00,
		sugar2 = 1.50,
		salt1 = 1.00,
		salt2 = 1.50,
		lemonjuice1 = 3.00,
		lemonjuice2 = 3.50,
		brownsugar1 = 2.00,
		brownsugar2 = 2.50,
		egg1 = 3.00,
		egg2 = 5.00,
		frankshotsauce1 = 3.00,
		frankshotsauce2 = 4.00,
		chocolatemilk1 = 2.00,
		chocolatemilk2 = 3.00,
		vanillaextract1 = 3.00,
		vanillaextract2 = 3.50,
		tax = 1.24;

	cout << "Hello there and welcome to our store! What would you like to order from our selections? Please enter a number labeled on each ingredient";
	cout << "\n";
	cout << "\n";
	cout << "1. Milk";
	cout << "\n";
	cout << "2. Sugar";
	cout << "\n";
	cout << "3. Salt";
	cout << "\n";
	cout << "4. Lemon Juice";
	cout << "\n";
	cout << "5. Brown Sugar";
	cout << "\n";
	cout << "6. Egg";
	cout << "\n";
	cout << "7. Frank's Hot Sauce";
	cout << "\n";
	cout << "8. Chocolate Milk";
	cout << "\n";
	cout << "9. Vanilla extract";
	cout << "\n";
	cout << "\n";

	cin >> ingredient1;
	if (ingredient1 == 1)
	{
		cout << "\n";
		cout << "What size of milk do you want? 1 or 2 gallon?";
		cout << "\n";
	}

	cin >> ingredient11;
	 if (ingredient11 == 1)
	{
		cout << "\n";
		cout << "1 gallon? I will put it in the cart for you. What else do you like to order?";
		cout << "\n";
	}

	 if (ingredient11 == 2)
	{
		cout << "\n";
		cout << "2 gallon? I will put it in the cart for you. What else do you like to order?";
		cout << "\n";
	}

	cin >> ingredient2;
	 if (ingredient2 == 2)
	{
		cout << "\n";
		cout << "What size of sugar do you want? 8 oz or 10 oz?";
		cout << "\n";
	}

	cin >> ingredient22;
	 if (ingredient22 == 8)
	{
		cout << "\n";
		cout << "8 oz? I will put it in the cart for you. What else do you like to order?";
		cout << "\n";
	}

	 if (ingredient22 = 10)
	{
		cout << "\n";
		cout << "10 oz? I will put it in the cart for you. What else do you like to order?";
		cout << "\n";
	}

	cin >> ingredient3;
	 if (ingredient3 == 3)
	{
		cout << "\n";
		cout << "What size of salt do you want? 2 oz or 4 oz?";
		cout << "\n";
	}

	cin >> ingredient33;
	 if (ingredient33 == 2)
	{
		cout << "\n";
		cout << "2 oz? I will put it in the cart for you. What else do you like to order?";
		cout << "\n";
	}

	 if (ingredient33 == 4)
	{
		cout << "\n";
		cout << "4 oz? I will put it in the cart for you. What else do you like to order?";
		cout << "\n";
	}

	cin >> ingredient4;
	 if (ingredient4 == 4)
	{
		cout << "\n";
		cout << "what size of lemon juice do you want? 12 oz or 16 oz?";
		cout << "\n";
	}

	cin >> ingredient44;
	 if (ingredient44 = 12)
	{
		cout << "\n";
		cout << "12 oz? I will put it in the cart for you. What else do you like to order?";
		cout << "\n";
	}

	 if (ingredient44 = 16)
	{
		cout << "\n";
		cout << "16 oz? I will put it in the cart for you.What else do you like to order?";
		cout << "\n";
	}

	cin >> ingredient5;
	 if (ingredient5 == 5)
	{
		cout << "\n";
		cout << "What size of brown sugar do you want? 1 oz or 6 oz?";
		cout << "\n";

	cin >> ingredient55;
	 if (ingredient55 = 1)
	{
		cout << "\n";
		cout << "1 oz? I will put it in the cart for you.What else do you like to order?";
		cout << "\n";
	}
	 if (ingredient55 = 6)
	{
		cout << "\n";
		cout << "6 oz? I will put it in the cart for you.What else do you like to order?";
		cout << "\n";
	}

	}
	cin >> ingredient6;
	 if (ingredient6 == 6)
	{
		cout << "\n";
		cout << "How many eggs do you want? 8 or 12 eggs?";
		cout << "\n";
	}

	cin >> ingredient66;
	 if (ingredient66 = 8)
	{
		cout << "\n";
		cout << "8 eggs? I will put it in the cart for you.What else do you like to order?";
		cout << "\n";
	}

	 if (ingredient66 = 12)
	{
		cout << "\n";
		cout << "12 eggs? I will put it in the cart for you. What else do you like to order?";
		cout << "\n";
	}

	cin >> ingredient7;
	 if (ingredient7 == 7)
	{
		cout << "\n";
		cout << "What size do you want for Frank's Hot Sauce? 3 oz or 5 oz?";
		cout << "\n";
	}

	cin >> ingredient77;
	 if (ingredient77 == 3)
	{
		cout << "\n";
		cout << "3 oz? I will put it in the cart for you. What else do you like to order?";
		cout << "\n";

	}

	 if (ingredient77 == 5)
	{
		cout << "\n";
		cout << "5 oz? I will put it in the cart for you. What else do you like to order?";
		cout << "\n";
	}

	cin >> ingredient8;
	 if (ingredient8 == 8)
	{
		cout << "\n";
		cout << "What size of chocolate milk do you want? 2 gallon or 4 gallon?";
		cout << "\n";
	}

	cin >> ingredient88;
	 if (ingredient88 == 2)
	{
		cout << "\n";
		cout << "2 gallons? I will put it in the cart for you. What else do you like to order?";
		cout << "\n";
	}

	 if (ingredient88 == 4)
	{
		cout << "\n";
		cout << "4 gallons? I will put it in the cart for you. What else do you like to order?";
		cout << "\n";
	}

	cin >> ingredient9;
	 if (ingredient9 == 9)
	{
		cout << "\n";
		cout << "What size of vanilla extract do you want? 1 cup or 2 cup?";
		cout << "\n";
	}

	cin >> ingredient99;
	 if (ingredient99 == 1)
	{
		cout << "\n";
		cout << "1 cup? I will put it in the cart for you. What else do you like to order?";
		cout << "\n";
	}

	 if (ingredient99 == 2)
	{
		cout << "\n";
		cout << "2 cup? I will put it in the cart for you. What else do you like to order?";
		cout << "\n";
	}

	return 0;
}
Your problem is assignment instead of comparison (lines 221/228):
1
2
3
4
5
6
7
8
9
10
11
12
13
14
	cin >> ingredient66;
	 if (ingredient66 = 8) // Note: assigns 8
	{
		cout << "\n";
		cout << "8 eggs? I will put it in the cart for you.What else do you like to order?";
		cout << "\n";
	}

	 if (ingredient66 = 12) // Note: assigns 12
	{
		cout << "\n";
		cout << "12 eggs? I will put it in the cart for you. What else do you like to order?";
		cout << "\n";
	}
As @coder777 pointed out, you're confusing yourself over the equality operator and the assignment operator. There's a few other places you have this error as well, namely lines 137, 176, 183, 198, and 204. Also you notice how you have so many repeated messages? I would recommend making a const string variable for that, like
const string confirmMessage = "I will put it in the cart for you. What else would you like to order?".

Also try tagging on endl instead of repeatedly using cout << "\n". In your ingredients menu alone it would cut down the length of the code by half.
Last edited on
Ohhh I see! That fixed the first problem I had. Thank you. Does anyone know how to fix the second problem?
It has to do with how you wrote your cin statements. Let's take the first one for your milk. What if I entered a number other than 1? The compiler has no way of differentiating that the number I entered in, say 3, was supposed to be for salt. All it knows is that it's supposed to take input for milk. And then it's supposed to take input for milk size.

In other words, you want to have some sort of if else or switch statement dictating which item(s) should go in the shopping cart.
The second problem is (like YFGHNG already stated) that on line 99 you have only one if (ingredient1 == 1) for milk. All other are missing.
Topic archived. No new replies allowed.