Errors to fix

My code has over 700 lines so I'll need to post it in chunks:

Error 1: I've purposely put the wrong file name in my loadRates function so I could work on the rest of the program and see how it runs. If I put the right file name, my error message for the taxrate repeats and won't stop.

Error 2: My final price before the receipt prints out is always $0.

Error 3: My cout for CART: in the receipt is always blank.

Error 4: In my emptyCart function, I don't know how to delete a single item and leave the rest in the cart. And would the code for if (num == 2) work if I wanted to empty the entire cart?

Question: How would I the user's name to printout in the cout message before the receipt? For some reason, it won't print out.

I'll post the code below. If anyone can help, thank you in advance. And if you happen to see any other errors, I'd appreciate that, too.
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
#include <iostream>
#include <iomanip>
#include <fstream>
#include <string>
#include <ctime>
using namespace std;

struct Info
{
	string zipcode;
	int ziplength;
	double taxrate;
	double USPS;
	double UPS;
	double fedEx;
};

struct Data
{
	string description;
	int height, width, length, weight, quantity, price;
};

struct Cart
{
	double price;
	int quantity;
	float subtotal;
	int num;
	double price1[5];
	char choice;
	double shipCost;
	double cost;
	string cart;
};

int maintainCart(Cart info)
{
	cout << "How many would you like to buy?" << endl;
	cin >> info.quantity;
	
	while (info.quantity < 1)
	{
		cout << "Invalid amount. You must choose one item.";
		cin >> info.quantity;
	}
	cout << endl;
	return 0;
}

string createCustomer (string name, string address)
{
	cout << "Time to create your customer account." << endl << endl;
	cout << "Please enter your name: ";
	cin >> name;
	cin.clear();
	cin.ignore();
	cout << "Please enter your address: ";
	getline(cin, address);
	cout << "Hello " << name << ", your address is " << address << "." << endl;
	cout << "Your customer account has been created!" << endl;
	cout << endl;
	return name;
	return address;
}

int displayMenu()
{
	int num;
	cout << "Please choose a menu option: " << endl;
	cout << "1. Create Customer Account" << endl;
	cout << "2. Shop for Items" << endl;
	cout << "3. Proceed to Checkout" << endl;
	cout << "4. Exit Store" << endl;
	cout << "5. Debug" << endl;
	cout << "6. Empty Cart" << endl;
	cin >> num;
	cout << endl;
	return num;
}

int displayCatalog()
{
	int num;
	do{
		cout << "Please choose the item you'd like to buy: " << endl;
		cout << "1. Ton-Tongue Toffee" << endl;
		cout << "2. Self-Writing Quill" << endl;
		cout << "3. Wildfire Whiz-bangs" << endl;
		cout << "4. Felix Felicis" << endl;
		cout << "5. Dragon Fire" << endl;
		cout << "6. Exit Store :(" << endl;
		cin >> num;

		if (num < 1 || num > 6)
			cout << "You picked in an invalid choice." << endl;
	}while (num < 1 || num >6);
	
	return num;
}

void itemRank (int num)
{
	if (num == 1)
		cout << "RATING: ***" << endl;
	else if (num == 2)
		cout << "RATING: ****" << endl;
	else if (num == 3)
		cout << "RATING: **" << endl;
	else if (num == 4)
		cout << "RATING: *" << endl;
	else 
		cout << "RATING: *****" << endl;
}

void crossSell (Cart info, int num)
{
	switch (num)
	{
	case 1:
		cout << "Recommendations: " << endl;
		cout << "1. The Elder Wand" << endl;
		cout << "2. The Sorceror's Stone" << endl;
		cout << "3. The Golden Snitch" << endl;
		cout << "Would you like to buy from these items? (Y or N)" << endl;
		cin >> info.choice;
			if (info.choice == 'y' || info.choice == 'Y')
			{
				cout << "What would you like to buy?" << endl;
				cout << "1. The Elder Wand" << endl;
				cout << "2. The Sorceror's Stone" << endl;
				cout << "3. The Golden Snitch" << endl;
				cin >> info.num;
					if (info.num == 1)
						maintainCart(info);
					else if (info.num == 2)
						maintainCart(info);
					else if (info.num == 3)
						maintainCart(info);
			}
			break;

	case 2:
		cout << "Recommendations: " << endl;
		cout << "1. The Basilisk Fang" << endl;
		cout << "2. Tom Riddle's Diary" << endl;
		cout << "3. Hogwarts: A History" << endl;
		cout << "Would you like to buy from these items? (Y or N)" << endl;
		cin >> info.choice;
			if (info.choice == 'y' || info.choice == 'Y')
			{
				cout << "What would you like to buy?" << endl;
				cout << "1. The Basilisk Fang" << endl;
				cout << "2. Tom Riddle's Diary" << endl;
				cout << "3. Hogwarts: A History" << endl;
				cin >> info.num;
					if (info.num == 1)
						maintainCart(info);
					else if (info.num == 2)
						maintainCart(info);
					else if (info.num == 3)
						maintainCart(info);
			}
			break;

	case 3:
		cout << "Recommendations: " << endl;
		cout << "1. Time-Turner" << endl;
		cout << "2. Hagrid's Umbrella" << endl;
		cout << "3. Pumpkin Juice" << endl;
		cout << "Would you like to buy from these items? (Y or N)" << endl;
		cin >> info.choice;
			if (info.choice == 'y' || info.choice == 'Y')
			{
				cout << "What would you like to buy?" << endl;
				cout << "1. Time-Turner" << endl;
				cout << "2. Hagrid's Umbrella" << endl;
				cout << "3. Pumpkin Juice" << endl;
				cin >> info.num;
					if (info.num == 1)
						maintainCart(info);
					else if (info.num == 2)
						maintainCart(info);
					else if (info.num == 3)
						maintainCart(info);
			}
			break;

	case 4:
		cout << "Recommendations: " << endl;
		cout << "1. The Elder Wand" << endl;
		cout << "2. R.A.B's Locket" << endl;
		cout << "3. Cornish Pixies" << endl;
		cout << "Would you like to buy from these items? (Y or N)" << endl;
		cin >> info.choice;
			if (info.choice == 'y' || info.choice == 'Y')
			{
				cout << "What would you like to buy?" << endl;
				cout << "1. The Elder Wand" << endl;
				cout << "2. R.A.B's Locket" << endl;
				cout << "3. Cornish Pixies" << endl;
				cin >> info.num;
					if (info.num == 1)
						maintainCart(info);
					else if (info.num == 2)
						maintainCart(info);
					else if (info.num == 3)
						maintainCart(info);
			}
			break;

	case 5:
		cout << "Recommendations: " << endl;
		cout << "1. Bertie Bott's Every Flavor Beans" << endl;
		cout << "2. The Sorting Hat" << endl;
		cout << "3. The Golden Snitch" << endl;
		cout << "Would you like to buy from these items? (Y or N)" << endl;
		cin >> info.choice;
			if (info.choice == 'y' || info.choice == 'Y')
			{
				cout << "What would you like to buy?" << endl;
				cout << "1. Bertie Bott's Every Flavor Beans" << endl;
				cout << "2. The Sorting Hat" << endl;
				cout << "3. The Golden Snitch" << endl;
				cin >> info.num;
					if (info.num == 1)
						maintainCart(info);
					else if (info.num == 2)
						maintainCart(info);
					else if (info.num == 3)
						maintainCart(info);
			}
			break;
		}
}

void catalogChoice(Cart info, double cost, double price1[], int&num)
{
	do{
		num = displayCatalog();
		switch (num)
		{
		case 1: //user buys toffee
			cout << "You've chosen Ton-Tongue Toffee." << endl;
			itemRank(1);
			cost = price1[0];
			cout << "Your current total is $" << cost << "." << endl;
			info.cart = info.cart + "Ton-Tongue Toffee";
			maintainCart(info);
			crossSell(info, num);
			break;
		case 2: //user buys quill
			cout << "You've chosen the Self-Writing Quill." << endl;
			itemRank(2);
			cost = price1[1];
			cout << "Your current total is $" << cost << "." << endl;
			info.cart = info.cart + + "Self-Writing Quill";
			maintainCart(info);
			crossSell(info, num);
			break;
		case 3: //user buys whiz-bangs
			cout << "You have picked the Wildfire Whizbangs." << endl;
			itemRank(3);
			cost = price1[2];
			cout << "Your current total is $" << cost << "." << endl;
			info.cart = info.cart + "Wildfire Whiz-bangs";
			maintainCart(info);
			crossSell(info, num);
			break;
		case 4: //user buys potion
			cout << "You have picked Felix Felicis." << endl;
			itemRank(4);
			cost = price1[3];
			cout << "Your current total is $" << cost << "." << endl;
			info.cart = info.cart + "Felix Felicis";
			maintainCart(info);
			crossSell(info, num);
			break;
		case 5: //user buys fire
			cout << "You have picked Dragon Fire." << endl;
			itemRank(5);
			cost = price1[4];
			cout << "Your current total is $" << cost << "." << endl;
			info.cart = info.cart + "Dragon Fire";
			maintainCart(info);
			crossSell(info, num);
			break;
		case 6: // exit store
			cout << "Thank you for visiting and have a nice day!" << endl;
			system("pause");
			exit(1);
			break;
		default:
			cout << endl;
			itemRank(0);
			maintainCart(info);
			crossSell(info, num);
			break;
		}

		//prompt user about shopping
		cout << "Would you like to continue shopping? (Y or N)";
		cin >> info.choice;
		cout << endl;
	}while (info.choice == 'y' || info.choice == 'Y');
}
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
void calculateShipDay(int&day, int&shipDay, int&num, double&cost, double&height, double&weight, double&length, double&width, double&rate, double&vol, double&ship, double&tax, double&shipCost)
{

	//user selected method
	cout << "What day of the month is it?" << endl;
	cin >> shipDay;
	cin.clear();
	cin.ignore();

	//ask user about shipping method
	cout << "Which shipping method do you want to use?" << endl;
	cout << "1. USPS (10 days)" << endl;
	cout << "2. UPS (7 days)" << endl;
	cout << "3. FedEx (4 days)" << endl;
	cin >> num;
	cin.clear();
	cin.ignore();
	cout << endl;

	switch (num)
	{
		case 1:
			day = 10;
			rate = 1.55;
			calculateShipping(cost, height, weight, length, width, rate, vol, ship, shipCost);
			tax = (tax*cost)/100;

			//estimate shipping date
			if (shipDay > 0 && shipDay < 19)
			{
				cout << "Your product will arrive on day " << (abs)(day + shipDay) << " of this month." << endl;
				cout << endl;
			}
			else if (shipDay >= 19 && shipDay <=30)
			{
				cout << "Your product will arrive on day " << (abs)(30 - (day + shipDay)) << " of next month." << endl;
				cout << endl;
			}
				break;

		case 2:
			day = 7;
			rate = 1.65;
			calculateShipping(cost, height, weight, length, width, rate, vol, ship, shipCost);
			tax = (tax*cost)/100;

			//estimate shipping date
			if (shipDay > 0 && shipDay < 27)
			{
				cout << "Your product will arrive on day " << (abs)(day + shipDay) << " of this month." << endl;
				cout << endl;
			}
			else if (shipDay >= 27 && shipDay <= 30)
			{
				cout << "Your product will arrive on day " << (abs)(30 - (day + shipDay)) << " of next month." << endl;
				cout << endl;
			}
				break;
		case 3:
			day = 4;
			rate = 1.72;
			calculateShipping(cost, height, weight, length, width, rate, vol, ship, shipCost);
			tax = (tax*cost)/100;

			//estimate shipping date
			if (shipDay > 0 && shipDay < 25)
			{
				cout << "Your product will arrive on day " << (abs)(day + shipDay) << " of this month." << endl;
				cout << endl;
			}
			else if (shipDay >= 25 && shipDay <= 30)
			{
				cout << "Your product will arrive on day " << (abs)(30 - (day + shipDay)) << " of next month." << endl;
				cout << endl;
			}
				break;
		default:
			day = 10;
			rate = 1.55;
			calculateShipping(cost, height, length, weight, width, rate, vol, ship, shipCost);
			tax = (tax*cost)/100;

			//estimate shipping date
			if (shipDay > 0 && shipDay < 19)
			{
				cout << "Your product will arrive on day " << (abs)(day + shipDay) << " of this month." << endl;
				cout << endl;
			}
			else if (shipDay >= 19 && shipDay <=30)
			{
				cout << "Your product will arrive on day " << (abs)(30 - (day + shipDay)) << " of next month." << endl;
				cout << endl;
			}
				break;
	}
}

float calculateSubtotal(float&subtotal, double shipCost, double cost, int quantity)
{
	subtotal = (shipCost + cost)*quantity;
	return subtotal;
}

float calculateTotal(float&tax, float&subtotal)
{
	float total;
	total = subtotal + tax;
	return total;
}

void testTax()
{
	double cityTax = 6.4;
	double cost = 7.00;
	float final = (cityTax*cost)/100;
	cout.setf(ios::fixed);
	cout.precision(2);
	cout.setf(ios::fixed);
	cout.precision(2);
	cout << "Test tax = $" << final << endl;
}

void testTotal()
{
	float tax = 0.45;
	float subtotal = 1145.60;
	float shipCost = 13.00;
	float final = tax + subtotal + shipCost;
	cout << "Test total = $" << final << endl;
}

void testShipping()
{
	double cost = 11.50;
	double height = 9;
	double weight = 5;
	double width = 5;
	double length = 3;
	double rate = 5.4;
	double vol;
	double ship;
	double shipCost;
	vol = height*width*length;
	ship = vol/1000;
	cout.setf(ios::fixed);
	cout.precision(2);
	float final = cost;
	cout << "Test shipping = $" << shipCost << endl;
}

void testSubtotal()
{
	int quantity = 4;
	double cost = 6.25;
	float subtotal = 90.14;
	subtotal = subtotal + (cost*quantity);
	float final = subtotal;
	cout << "Test subtotal = $" << final << endl;
}

int loadRates (Info rates [])
{
	int i = 0;
	ifstream inStream;
	inStream.open("zipcode-list.txt");

		if (inStream.fail())
		{
		cout << "File couldn't be opened!" << endl;
		return -1;
		}
		
	while (i < 3000)
	{ 
		inStream >> rates[i].zipcode >> rates[i].taxrate >> rates[i].USPS >> rates[i].UPS >> rates[i].fedEx >> rates[i].ziplength;
		if (rates[i].ziplength > 5)
			cout << "Invalid zipcode!" << endl;
		else if (rates[i].taxrate > 1  || rates[i].taxrate < 0)
			cout << "Invalid taxrate!" << endl;
		else if (rates[i].USPS < 0)
			cout << "Invalid USPS rate!" << endl;
		else if (rates[i].UPS < 0)
			cout << "Invalid UPS rate!" << endl;
		else if (rates[i].fedEx < 0)
			cout << "Invalid FedEx rate!" << endl;
		else i++;
	}

	inStream.close();
	return i;
}

void emptyCart(int&num, char&choice, string&cart)
{
	cout << "Would you like to empty your cart? (Y or N)" << endl;
	cin >> choice;
	if (choice == 'y' || choice == 'Y')
	{
	cout << "Choose between: " << endl;
	cout << "1. A specific item" << endl;
	cout << "OR" << endl;
	cout << "2. The whole cart" << endl;
	cin >> num;
	cin.clear();
	cin.ignore();

		if(num == 1)
		{
			cout << "What item would you like to remove?" << endl;
			cin >> num;
		}
	
		else if(num == 2)
		{
			cart = " ";
		}
	}

	else displayMenu();
}
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
int main()
{
	srand((unsigned)time(NULL));

	//define and initialize variables needed

	int num;
	int cityChoice;
	int day;
	int shipDay;
	char choice = '\0';
	string name;
	string address;
	string cart = " " ;
	double price1[5] = {0, 0, 0, 0, 0};
	price1[0] = rand()%5+10;
	price1[1] = rand()%5+10;
	price1[2] = rand()%10+10;
	price1[3] = rand()%10+20;
	price1[4] = rand()%20+40;
	double price = 0;
	int quantity = 0;
	double cost = 0.0;
	float subtotal = 0;
	float total = 0.0;
	float cityTax = 0.0;
	double tax = 0.0;
	float tax1 = 0.0;
	double ship = 0.0;
	double vol = 0.0;
	double height = 0.0;
	double weight = 0.0;
	double length = 0.0;
	double width = 0.0;
	double rate = 0.0;
	double shipCost = 0.0;
	Info rates [3000];
	Cart info;

	int cnt = loadRates(rates);
	for (int i = 0; i < cnt; i++)
	{
		cout << rates[i].zipcode << endl;
		cout << rates[i].USPS << endl;
		cout << rates[i].UPS << endl;
		cout << rates[i].fedEx << endl;
	}
	system("pause");
	cout << endl;

	//display menu to user
	cout << "Welcome to Weasleys' Wizard Wheezes." << endl;

	do{
		num = displayMenu();
		if (num == 1)
		{
			createCustomer(name, address);
		}

		else if (num == 2)
		{
			catalogChoice(info, cost, price1, num);
		}

		else if (num == 3)
		{
			tax = calculateTax(tax1, cost, quantity, ship, height, weight, length, width, rate, vol, day, shipDay);
            cout << "The tax is $" << tax << "." << endl;
			calculateShipDay(day, shipDay, num, cost, height, weight, length, width, rate, vol, ship, tax, shipCost);
			subtotal = calculateSubtotal(subtotal, cost, total, quantity);
            total = calculateTotal(tax1, subtotal);
            cout << "Your final price is: $" << total + shipCost << endl;
            break;
		}

		else if (num == 4)
		{
			cout << "Thank you for visiting Weasleys' Wizard Wheezes. Have a nice day!" << endl;
			system("pause");
			exit(1);
		}

		else if (num == 5)
		{
			testTax();
			testShipping();
			testSubtotal();
			testTotal();
		}

		else if (num == 6)
		{
			emptyCart(num, choice, cart);
		}

		else cout << "You've chosen an invalid option. Please choose again." << endl;
	
	}while(num != 6);

	//validate purchase
	cout << "Are you sure you want to buy this? (Y or N)" << endl;
	cin >> choice;
	cart = info.cart;
	if ((choice == 'y' || choice == 'Y'))
	{
		cout << name <<  ", we appreciate your patronage here at our shop!" << endl;
		cout << "Here's what you've bought: " << endl;
		cout << "-------------------------------------" << endl;
		cout << "CART:          " << cart << endl;
		cout << "SUBTOTAL:        $" << subtotal << endl;
		cout << "SHIPPING:        $" << shipCost << endl;
		cout << "TAX:             $" << tax << endl;
		cout << "TOTAL:             "<< total << endl;
		cout << "Have a nice day!" << endl;
		system("pause");
		exit(1);
	}

	else if ((choice == 'n' || choice == 'N'))
	{
		cout << "Thanks for your time. Have a wonderful day!" << endl;
		system("pause");
		exit(1);
	}
	
	else cout << "Empty cart!" << endl;

	system("pause");
	return 0;
}
I'll be honest with you I don't feel like reading all of that code. I would say you could have easily cut off a third of it using loops like here the switch statements in the first two code posts. Also generally speaking when you have something that you are going to repeat more than once you want to put it in a subprogram then call it multiple times instead of inlining it multiple times.
I would also advice you not to use system("anything") it could lead to problems later on and it is not cross-platform.

You are doing integer division numerous times when it should be a floating point division
1
2
3
tax = (tax*cost)/100; //int division
ship = vol/1000; //int division
float final = (cityTax*cost)/100; //int division 


a) cast to a double or float
b) put . or .0 at end ( another way to convert to double )
c) put f , .f , .0f at the end of it to make it a float

integer division is like this 10 / 3 = 3
floating-point division is like this 10 / 3.0 = 3.33333

That is the reason you are getting the wrong result.

I can check out your code some more in depth tomorrow but probably wont be until evening for me.
I definitely don't like all this code, either. But based on my project's demands, any loop I've learned wouldn't have worked. Each case is different, which is why I used switch statements, though they have similar steps. Thanks for what you did help me with, though. I have to turn it in by midnight tonight so don't worry about it.
Here is what I mean for example:

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
switch (num)
		{
		case 1: //user buys toffee
			cout << "You've chosen Ton-Tongue Toffee." << endl;
			itemRank(1);
			cost = price1[0];
			cout << "Your current total is $" << cost << "." << endl;
			info.cart = info.cart + "Ton-Tongue Toffee";
			maintainCart(info);
			crossSell(info, num);
			break;
		case 2: //user buys quill
			cout << "You've chosen the Self-Writing Quill." << endl;
			itemRank(2);
			cost = price1[1];
			cout << "Your current total is $" << cost << "." << endl;
			info.cart = info.cart + + "Self-Writing Quill";
			maintainCart(info);
			crossSell(info, num);
			break;
		case 3: //user buys whiz-bangs
			cout << "You have picked the Wildfire Whizbangs." << endl;
			itemRank(3);
			cost = price1[2];
			cout << "Your current total is $" << cost << "." << endl;
			info.cart = info.cart + "Wildfire Whiz-bangs";
			maintainCart(info);
			crossSell(info, num);
			break;
		case 4: //user buys potion
			cout << "You have picked Felix Felicis." << endl;
			itemRank(4);
			cost = price1[3];
			cout << "Your current total is $" << cost << "." << endl;
			info.cart = info.cart + "Felix Felicis";
			maintainCart(info);
			crossSell(info, num);
			break;
		case 5: //user buys fire
			cout << "You have picked Dragon Fire." << endl;
			itemRank(5);
			cost = price1[4];
			cout << "Your current total is $" << cost << "." << endl;
			info.cart = info.cart + "Dragon Fire";
			maintainCart(info);
			crossSell(info, num);
			break;


Could have been:

1
2
3
4
5
6
7
8
9
10
11
string type[5] = { "Ton-Tongue Toffee" , "Self-Writing Quill" ,
				"Wildfire Whizbangs" , "Felix Felicis" , 
				"Dragon Fire" };
				
cout << "You have picked" << type[num-1] << '.' << endl;
itemRank(num);
cost = price1[num-1];
cout << "Your current total is $" << cost << '.' << endl;
info.cart += type[num-1];
maintainCart(info);
crossSell(info,num);


Since they all have the same thing except a different index.
Oh, I can use an array! I never thought of that. Okay, that would make a lot more sense. Thanks!
I have two errors C3861 in my displayCatalog function and they have to do with two following functions. It says the identifiers for my itemRank and crossSell functions aren't found. Can anyone help me find the error?

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
int displayCatalog(Cart info, float price1[], int i)
{
	do{
	cout << "Please choose the item you'd like to buy: " << endl;
	cout << "1. Ton-Tongue Toffee" << endl;
	cout << "2. Self-Writing Quill" << endl;		
	cout << "3. Wildfire Whiz-bangs" << endl;
	cout << "4. Felix Felicis" << endl;
	cout << "5. Dragon Fire" << endl;
	cout << "6. Exit Store :(" << endl;
	cin >> i;
	}while(i < 1 || i > 6);

		if (i < 1 ||i > 6)
			cout << "You picked in an invalid choice." << endl;

	string item [5] = {"Ton-Tongue Toffee", "Self-Writing Quill", "Wildfire Whizbangs", "Felix Felicis", "Dragon Fire"};
	for (i = 1; i <= 5; i++)
	{
		cout << "You've chosen " << item[i] << "." << endl;
		itemRank(i); // error C3861
		float cost = price1[i];
		cout << "Your current total is $" << cost << "." << endl;
		info.cart += item[i];
		maintainCart(info);
		crossSell(info, i); // error C3861
	}
	return i;
}

void itemRank (int&i)
{
	if (i == 1)
		cout << "RATING: ***" << endl;
	else if (i == 2)
		cout << "RATING: ****" << endl;
	else if (i == 3)
		cout << "RATING: **" << endl;
	else if (i == 4)
		cout << "RATING: *" << endl;
	else 
		cout << "RATING: *****" << endl;
}

void crossSell (Cart info, int&i)
{
	switch (i)
	{
	case 1:
		cout << "Recommendations: " << endl;
		cout << "1. The Elder Wand" << endl;
		cout << "2. The Sorceror's Stone" << endl;
		cout << "3. The Golden Snitch" << endl;
		cout << "Would you like to buy from these items? (Y or N)" << endl;
		cin >> info.choice;
			if (info.choice == 'y' || info.choice == 'Y')
			{
				cout << "What would you like to buy?" << endl;
				cout << "1. The Elder Wand" << endl;
				cout << "2. The Sorceror's Stone" << endl;
				cout << "3. The Golden Snitch" << endl;
				cin >> info.i;
					if (info.i == 1)
						maintainCart(info);
					else if (info.i == 2)
						maintainCart(info);
					else if (info.i == 3)
						maintainCart(info);
			}
			break;

	case 2:
		cout << "Recommendations: " << endl;
		cout << "1. The Basilisk Fang" << endl;
		cout << "2. Tom Riddle's Diary" << endl;
		cout << "3. Hogwarts: A History" << endl;
		cout << "Would you like to buy from these items? (Y or N)" << endl;
		cin >> info.choice;
			if (info.choice == 'y' || info.choice == 'Y')
			{
				cout << "What would you like to buy?" << endl;
				cout << "1. The Basilisk Fang" << endl;
				cout << "2. Tom Riddle's Diary" << endl;
				cout << "3. Hogwarts: A History" << endl;
				cin >> info.i;
					if (info.i == 1)
						maintainCart(info);
					else if (info.i == 2)
						maintainCart(info);
					else if (info.i == 3)
						maintainCart(info);
			}
			break;

	case 3:
		cout << "Recommendations: " << endl;
		cout << "1. Time-Turner" << endl;
		cout << "2. Hagrid's Umbrella" << endl;
		cout << "3. Pumpkin Juice" << endl;
		cout << "Would you like to buy from these items? (Y or N)" << endl;
		cin >> info.choice;
			if (info.choice == 'y' || info.choice == 'Y')
			{
				cout << "What would you like to buy?" << endl;
				cout << "1. Time-Turner" << endl;
				cout << "2. Hagrid's Umbrella" << endl;
				cout << "3. Pumpkin Juice" << endl;
				cin >> info.i;
					if (info.i == 1)
						maintainCart(info);
					else if (info.i == 2)
						maintainCart(info);
					else if (info.i == 3)
						maintainCart(info);
			}
			break;

	case 4:
		cout << "Recommendations: " << endl;
		cout << "1. The Elder Wand" << endl;
		cout << "2. R.A.B's Locket" << endl;
		cout << "3. Cornish Pixies" << endl;
		cout << "Would you like to buy from these items? (Y or N)" << endl;
		cin >> info.choice;
			if (info.choice == 'y' || info.choice == 'Y')
			{
				cout << "What would you like to buy?" << endl;
				cout << "1. The Elder Wand" << endl;
				cout << "2. R.A.B's Locket" << endl;
				cout << "3. Cornish Pixies" << endl;
				cin >> info.i;
					if (info.i == 1)
						maintainCart(info);
					else if (info.i == 2)
						maintainCart(info);
					else if (info.i == 3)
						maintainCart(info);
			}
			break;

	case 5:
		cout << "Recommendations: " << endl;
		cout << "1. Bertie Bott's Every Flavor Beans" << endl;
		cout << "2. The Sorting Hat" << endl;
		cout << "3. The Golden Snitch" << endl;
		cout << "Would you like to buy from these items? (Y or N)" << endl;
		cin >> info.choice;
			if (info.choice == 'y' || info.choice == 'Y')
			{
				cout << "What would you like to buy?" << endl;
				cout << "1. Bertie Bott's Every Flavor Beans" << endl;
				cout << "2. The Sorting Hat" << endl;
				cout << "3. The Golden Snitch" << endl;
				cin >> info.i;
					if (info.i == 1)
						maintainCart(info);
					else if (info.i == 2)
						maintainCart(info);
					else if (info.i == 3)
						maintainCart(info);
			}
			break;
		}
}
Cut and paste the two functions above your displayCatalog function or declare their protypes at the top of your program.

This is because if you use a function in a second function's definition it must have been declared or defined before that second function.

Declaring all your function prototypes at the top of your program means that when you define your functions lower in the program every function knows your function names.
Thanks for your help!
At this specific part, how can I get my rates to stop repeating? I have a file of about 2600 California zipcodes to read through and test for errors. But only the first 15 have errors. The code still needs to read through all of the zipcodes.

1
2
3
4
5
6
7
8
9
struct Info
{
	string zipcode;
	int ziplength;
	double taxrate;
	double USPS;
	double UPS;
	double fedEx;
};


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
int loadRates (Info rates [])
{
	int i = 0;
	ifstream inStream;
	inStream.open("zipcode-list.txt");

		if (inStream.fail())
		{
		cout << "File couldn't be opened!" << endl;
		return -1;
		}
		
	while (i < 3000)
	{ 
		inStream >> rates[i].zipcode >> rates[i].taxrate >> rates[i].USPS >> rates[i].UPS >> rates[i].fedEx >> rates[i].ziplength;
		if (rates[i].ziplength > 5)
			cout << "Invalid zipcode!" << endl;
		else if (rates[i].taxrate > 1  || rates[i].taxrate < 0)
			cout << "Invalid taxrate!" << endl;
		else if (rates[i].USPS < 0)
			cout << "Invalid USPS rate!" << endl;
		else if (rates[i].UPS < 0)
			cout << "Invalid UPS rate!" << endl;
		else if (rates[i].fedEx < 0)
			cout << "Invalid FedEx rate!" << endl;
		else i++;
	}

	inStream.close();
	return i;
}
how about on line 13 instead of reading for 3000 times (magic number?) you read while it is good( while it can read in data).
Topic archived. No new replies allowed.