Prompt skipped and error reading a file.

So, here's my conundrums.
First, for some reason, the program skips the prompt for name (line 65-66) and goes straight to street. The code is written the same way throughout that section to my eye. I can't see what I've left out or put in extra.

Secondly, if the user chooses option 2 the program is supposed to load a file (Mailings.txt) and read the info. Below is the first of five "entries" from the .txt file.

Ann Perkins
217 Lowell Drive
Pawnee
IN
47408
3
4.2

Each line should correspond to the name, street, city, state, zip string variable for the address. 3 and 4.2 correspond to the package type and weight in ounces. So, my program should open Mailings.txt, read each line, use package choice and weight to calculate shipping charges and print a mailing label a total of 5 times. I tried to write the program so that it would loop for 'x' number of entries. When I run the program though it's not taking each line as string. And it doesn't loop back to display all the entries. The program only displays part of the first entry.

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
  /*CSC 134 80
Project 3 Postal Bar Code and Mailings List
Josh Krynock 
This program displays a menu for single or multiple mailings. It will 
ask the user what type of item is being mailed and for the item's weight.
The program will then calculate the postage and generate a mailing label
complete with barcode. If the user selects multiple mailings, the program
will read a file, Mailings.txt, and generate a list of postage costs and
mailing labels for each. */

#include <iostream>
#include <iomanip>
#include <string>
#include <fstream>
using namespace std;

int main()
{
	//Variables for menu.
	int choice;
	//Variables for string input
	string name, street, city, state;
	// Variables for the zip code math. 
	int zip, check,
		ones,
		tens, tensA, 
		hund, hundA, 
		thou, thouA, 
		tenK, tenKA, 
		sum;
	//Variables for Postage rates
	int package, weight;
	//These are the shipping rate variables
	const double 	LETTER = 0.49,
					LETTERplus = 0.22,
					ENVELOPE = 0.98,
					ENVELOPEplus = 0.22,
					PARCEL = 2.54,
					PARCELplus = 0.20,
					WEIGHT_MIN = 0.0, WEIGHT_MAX = 1.0;
	double postage;
	//These are the variables to store the bar code.
	string bar1, bar10, bar100, bar1k, bar10k, barcheck;
	
	//Format numeric output.
	cout << fixed << showpoint << setprecision(2);
	
	do 
	{	
	cout << "Welcome to the Mailing Label System\n\n";
	cout << "1 - Single Mailings\n";
	cout << "2 - Multiple Mailings\n";
	cout << "3 - Quit\n";
	cout << "Enter your choice: ";
	cin >> choice;
	}
	while (choice < 1 || choice > 3 );
	
	/*Choice #1 procudure. 
	  Validation of zip code, parcel selection, and weight
	  occur within the do-while loops.
	  */
	if (choice == 1)
	{
		cout << "Enter name: ";
		getline(cin, name);
		cout << "Enter street address: ";
		getline(cin, street);
		cout << "Enter City: ";
		getline(cin, city);
		cout << "Enter state: ";
		getline(cin, state);
		do
		{
		cout << "Enter zip code: ";
		cin >> zip;
		}
		while (zip < 501 || zip > 99950);
		do
		{
		cout << "Enter 1 for letter, 2 for envelope, 3 for parcel: ";
		cin >> package;
		}
		while (package < 1 || package > 3);
		do 
		{
		cout << "Enter the weight in ounces: ";
		cin >> weight;
		}
		while (weight <= 0);
		//This part of the program calculates shipping charges.
		if (package == 1)
		{
			if (weight <= WEIGHT_MAX && weight > WEIGHT_MIN)
				postage = LETTER;
			else
			{	static_cast<int>(weight);
				postage = (LETTER + (weight * LETTERplus));
			}
		}
		else if (package == 2)
		{
			if (weight <= WEIGHT_MAX && weight > WEIGHT_MIN)
				postage = ENVELOPE;
		
			else
			{	static_cast<int>(weight);
				postage = (ENVELOPE + (weight * ENVELOPEplus));
			}
		
		}
		else if (package == 3)
		{
			if (weight <= WEIGHT_MAX && weight > WEIGHT_MIN)
				postage = PARCEL;
		
		else
		{	static_cast<int>(weight);
			postage = (PARCEL + (weight * PARCELplus));
		}
		}
		//This part of the program breaks the zipcode into single digits.
		//First the ones, 
	 
		ones = zip % 10;
	
		//then tenths
		tens = zip % 100; 
		tensA = (tens - ones) / 10;
	
		//Hundreths
		hund = zip % 1000;
		hundA = (hund - tens) / 100;
	
		//Thousandths
		thou = zip % 10000;
		thouA = (thou - hund) / 1000;
	
		//Ten K
		tenK = zip % 100000;
		tenKA = (tenK - thou) / 10000;	
	 
		//This part of the program calculates the check number. 
		check = (ones - tensA + hundA + thouA + tenKA);
		check %= 10;
		check = (10-check);
	
		//This part of the program modifies the zip code to display 
		//it in true barcode form. 
		
	

	
	
		
		//This part of the program displays the postage label.
		cout << "\n\n\n\n";
		cout << left << "**********************************$";
		cout << postage << "\n\n";
		cout << name << "\n";
		cout << street << "\n";
		cout << city << ", " << state << " " << zip << "\n\n";
		cout << "|" << bar10k << bar1k << bar100 << bar10 << bar1 << barcheck << "|";	
	//Line 127 is the last bracket for choice #1 if block. 	
	}

	else if (choice == 2)
	{
		ifstream mailingList;
		mailingList.open("C:\\Users\\Josh\\Documents\\CPCC\\Spring 2016\\CSC 134 18\\Module 6\\Mailings.txt");	
		//Testing file opening
		if (mailingList.fail())
		{
			cout << "Error opening file. ";
			return 0;
		}
		else 
		{	//This section reads the info from the Mailings.txt file.
			//Information should be processed and looped. 
			while (mailingList >> name)
			{
				mailingList >> street;
				mailingList >> city;
				mailingList >> state;
				mailingList >> zip;
				mailingList >> package;
				mailingList >> weight;
				
				//This section calculates postage charges. Line 328 - 356
				if (package == 1)
				{
					if (weight <= WEIGHT_MAX && weight > WEIGHT_MIN)
						postage = LETTER;
					else
					{	static_cast<int>(weight);
						postage = (LETTER + (weight * LETTERplus));
					}	
				}
				else if (package == 2)
				{
					if (weight <= WEIGHT_MAX && weight > WEIGHT_MIN)
						postage = ENVELOPE;
					else
					{	static_cast<int>(weight);
						postage = (ENVELOPE + (weight * ENVELOPEplus));
					}
		
				}
				else if (package == 3)
				{
					if (weight <= WEIGHT_MAX && weight > WEIGHT_MIN)
					postage = PARCEL;
		
					else
					{	static_cast<int>(weight);
						postage = (PARCEL + (weight * PARCELplus));
					}
				}
				
				//This section calculates the check code and converts
				//the zip code into bar code format. Lines 362 - 383
				//First the ones, 
	 
				ones = zip % 10;
	
				//then tenths
				tens = zip % 100; 
				tensA = (tens - ones) / 10;
	
				//Hundreths
				hund = zip % 1000;
				hundA = (hund - tens) / 100;
	
				//Thousandths
				thou = zip % 10000;
				thouA = (thou - hund) / 1000;
	
				//Ten K
				tenK = zip % 100000;
				tenKA = (tenK - thou) / 10000;	
	 
				//This part of the program calculates the check number. 
				check = (ones - tensA + hundA + thouA + tenKA);
				check %= 10;
				check = (10-check);
				
				cout << "\n";
				cout << left << "**********************************$";
				cout << postage << "\n";
				cout << name << "\n";
				cout << street << "\n";
				cout << city << ", " << state << " " << zip << "\n";
				cout << "|" << bar10k << bar1k << bar100 << bar10 << bar1 << barcheck << "|";
			}//Last bracket for reading mailing list
			
		}
		mailingList.close();
		
	}
	else if (choice == 3)
		cout << "Thank you. Closing program.";
	return 0;
}
In order to get the post to post I had to delete a bunch of code. I took out the portion that converts a zip code number into a bar code of : and |
I ended up adding a cin.ignore() after line 65 of the code and that solved my first problem.
Hi Josh, I also have to complete a Postal Barcode project and would like to know what steps you used to convert the zip code to a barcode. Ive tried for hours trying to use a switch function but it hasnt worked out for me. Please help.
Topic archived. No new replies allowed.