Do While Skipping Line

Whenever the program loops back to the beginning to re enter the customer name, it skips the "Enter the name of the purchaser:" (line 27)prompt and goes straight to the address prompt (line 30) that immediately follows. It works fine the first time through, only when the loop repeats is there an issue.

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

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

int main()
{
	//Numeric variables needed for containers, zipcode, mathematical operations
	int doflingy, huge, large, medium, small, zipcode, hremain, lremain, customers = 1;
	double doflingyTotal, shippingTotal, taxTotal, orderTotal;
	//Shipping information entered by user
	string name, address, city, state;
	//char for user to enter another customer
	char moreCustomers = 'Y';
	//sales tax, doflingy cost, and shipping constants
	const double SALES_TAX = .0775; 
	const double HUGE_SHIPPING = 4.0, LARGE_SHIPPING = 2.0, MED_SHIPPING = 0.75, SMALL_SHIPPING = 0.2;
	const double _500_PLUS_COST = 15.95, _250_TO_499_COST = 17.50, _100_TO_249_COST = 18.95, TO_99_COST = 19.95;
	
	
	do
	{
		//Series of prompts for the user to enter customer shipping info
	
		cout << "Enter the name of the purchaser: ";
		getline(cin, name);
	
		cout << "Enter street address: ";
		getline(cin, address);
	
		cout << "Enter city: ";
		getline(cin, city);
	
		cout << "Enter state: ";
		getline(cin, state);
	
		cout << "Enter zipcode: ";
		cin >> zipcode;
	
		//Prompt for number of doflingies ordered, validates order size
		do
		{
			cout << "\nEnter the number of doflingies ordered: ";
			cin >> doflingy;
			if(doflingy < 10 || doflingy > 1000)
				cout << "\nOrders less than 10 or greater than 1000 will not be accepted." << endl;	
		}while(doflingy < 10 || doflingy > 1000);
	
	cout << endl << endl << endl;
	
	//variable declaration for printing options
	int printChoice;

	
		do
		{
		//Prompt for order receipt or shipping invoice
	
			cout << "Please select from the following options:" << endl;
			cout << "-----------------------------------------" << endl << endl;
			cout << "1.) Create shipping invoice" << endl;
			cout << "2.) Create customer receipt" << endl;
			cout << "3.) Exit" << endl << endl;
			cin >> printChoice;
			cout << endl;
	
			if(printChoice == 3)
				break;
			else if (printChoice == 1)
			{
			//Output of entered shipping information and number of doflingies ordered
			//Beginning of customer invoice/receipt
			ofstream outputFile;
			outputFile.open("Shipping_invoice.txt");
		
			outputFile << "----------------------------------------" << endl;
			outputFile << "                 INVOICE                " << endl;
			outputFile << "----------------------------------------" << endl << endl;
	
			outputFile << left << setw(17) << "\nShip To:" << name << endl;
			outputFile << "                " << address << endl;
			outputFile << "                " << city << ", " << state << "  " << zipcode << endl << endl;
	
			outputFile << "No. of Doflingies: " << doflingy << endl << endl;
	
			//Calculations for each size of container needed for shipping
			huge = doflingy / 50;
			hremain = doflingy%50;
			large = hremain/20;
			lremain = hremain%20;
			medium = lremain/5;
			small = lremain%5;
	
			//Output of number of each container required for this shipment		
			outputFile << "Container Size           Number Required" << endl;
			outputFile << "--------------           ---------------" << endl;
			outputFile << "    Huge                 " << setw(15) << right << huge << endl;
			outputFile << "    Large                " << setw(15) << right << large << endl;
			outputFile << "    Medium               " << setw(15) << right << medium << endl;
			outputFile << "    Small                " << setw(15) << right << small << endl;
			outputFile << "----------------------------------------" << endl << endl << endl;
		
			outputFile.close();
		
			cout << "\n\nThe invoice has been created and labeled Shipping_invoice.txt." << endl;
			cout << "\nPrint now if printing mutliple invoices as a new invoice" << endl;
			cout << "will erase current one." << endl << endl;
			cout << "*****************************************" << endl << endl;
			}
	
			else if (printChoice == 2)
			{
				//Calculating doflingy cost
				if(doflingy>=500)
					doflingyTotal = doflingy * _500_PLUS_COST;
				else if(doflingy>=250)
					doflingyTotal = doflingy * _250_TO_499_COST;
				else if(doflingy>=100)
					doflingyTotal = doflingy * _100_TO_249_COST;
				else
					doflingyTotal = doflingy * TO_99_COST;
		
				//Calculating shipping
				shippingTotal = (huge*HUGE_SHIPPING)+(large*LARGE_SHIPPING)+(medium*MED_SHIPPING)+(small*SMALL_SHIPPING);
	
				//Calculating sales tax
				taxTotal = (doflingyTotal + shippingTotal) * SALES_TAX;
	
				//Calculating order total
				orderTotal = doflingyTotal + shippingTotal + taxTotal;
	
				//Customer receipt
				ofstream outputFile;
				outputFile.open("Customer_receipt.txt");
		
				outputFile << "----------------------------------------" << endl;
				outputFile << "                 RECEIPT                " << endl;
				outputFile << "----------------------------------------" << endl << endl;
	
				outputFile << left << setw(17) << "\nShip To:" << name << endl;
				outputFile << "                " << address << endl;
				outputFile << "                " << city << ", " << state << "  " << zipcode << endl << endl;
	
				outputFile << "No. of Doflingies: " << doflingy << endl << endl;
		
				outputFile << "------------------Cost------------------" << endl << endl;
				outputFile << setprecision(2) << fixed;
				outputFile << "Doflingies               $" << setw(14) << right << doflingyTotal << endl;
				outputFile << "Shipping & Handling      $" << setw(14) << right << shippingTotal << endl;
				outputFile << "Sales Tax                $" << setw(14) << right << taxTotal << endl;
				outputFile << "                         _______________" << endl;
				outputFile << "Total                    $" << setw(14) << right << orderTotal << endl;
		
				outputFile.close();
		
				cout << "\n\nThe receipt has been created and labeled Customer_receipt.txt." << endl;
				cout << "\nPrint now if printing mutliple receipts as the next" << endl;
				cout << "receipt will erase current one." << endl << endl;
				cout << "*****************************************" << endl << endl;
			}
			else
				cout << "Invalid selection." <<endl << endl;

		}while (printChoice != 3);
		
		cout << "Would you like to enter another customer's information? (Y/N) ";
		cin >> moreCustomers;
		
	

	}while (moreCustomers == 'Y' || moreCustomers == 'y');
	
	return 0;
}
And I figured out a workaround. Put


cin.ignore(1000, '\n');


at the beginning, working fine now.

I'll leave this for posterity, ha.
Topic archived. No new replies allowed.