Help with formatting?

I can't seem to make the emp. no. employee counter appear in its proper position.I have been trying endlessly now. any help would be appreciated:


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
#include<iostream>
#include<fstream>
#include<string>
#include<iomanip>


using namespace std;
ifstream input;

void instruction()
{
	cout << "This payroll program calculates individual employee pay and company\n"
		<< "totals using data from a data file payroll.txt . ";

}

void reportTitle()
{
	cout         << left << setw(5) << "Emp."  
		         << left << setw(26) << "Employee"
				 << left << setprecision(2)<< setw(9) << fixed << "Hourly"
				 << left << setprecision(2)<< setw(9) << fixed << "Hours"
				 << left << setprecision(2)<< setw(9) << fixed << "Tax"
				 << left << setprecision(2)<< setw(9) << fixed << "Gross"
				 << left << setprecision(2)<< setw(9) << fixed << "Net";
	cout << "\n";

	cout		 << left << setw(5) << "No."   
				 << left << setw(26) << "Name"
				 << left << setprecision(2)<< setw(9) << fixed << "Rate"
				 << left << setprecision(2)<< setw(9) << fixed << "Worked"
				 << left << setprecision(2)<< setw(9) << fixed << "Rate"
				 << left << setprecision(2)<< setw(9) << fixed << "Amount"
				 << left << setprecision(2)<< setw(9) << fixed << "Amount";
	cout << "\n\n";


}

void reader(double& hourRate, double& workHours, double& taxRate, double& grossPay, string& empName)
{
	getline(input, empName, '#');
	input >> hourRate;
	input >> workHours;
	input >> taxRate;
	


}

void calc(double& grossPay, double& tax, double& netPay, double& totalNet, double& totalGross, double workHours, double hourRate, double taxRate)
{
	grossPay= workHours * hourRate;
	tax= grossPay*(taxRate/90);
	netPay= grossPay- tax;
	totalGross+=grossPay;
	totalNet+=netPay;
			

}

int main()
{
	instruction();
	input.open("payroll.txt");

	string empName;
	double hourRate=0;
	double workHours=0;
	double taxRate=0;
	double grossPay=0 ;
	double	netPay=0;
	double tax=0;
	double totalGross=0;
	double totalNet=0;
	cout << "\n\n";
    reportTitle();
	cout.flush();
	int counter=1;
//beginning of loop
	do
	{
	reader(hourRate, workHours, taxRate, grossPay, empName);
	calc(grossPay, tax, netPay, totalNet, totalGross, workHours, hourRate, taxRate);
	
	cout << setw(5) << counter 
		<< setw(25) << left << empName
				
				 << left << setprecision(2)<< setw(10) << fixed << showpoint << hourRate 
				 << left << setprecision(2)<< setw(10) << fixed << showpoint << workHours
				 << left << setprecision(2)<< setw(10) << fixed << showpoint << taxRate 
				 << left << setprecision(2)<< setw(10) << fixed << showpoint << grossPay 
				 << left << setprecision(2)<< setw(10) << fixed << showpoint << netPay;

	counter++;
	
	
	}while(!input.eof());
	


	
	
	
	cout << "\n\n";
	cout  << setw(58) << "Total: " 
		  <<  setw(9) << left << totalGross 
		  <<  setw(9) << left  << totalNet;
	
	cout << "\n\n\n";

	return 0;

	

	
}





here is the contents of payroll.txt:
John Smith#10.45 40 15
Jane Doe#12.50 45 15
Harry Morgan#20.00 40 20
Carmen Martinez#25.00 35 25
Jacintha Washington#50.85 60 35
1
2
3
4
5
6
7
8
void reader(double& hourRate, double& workHours, double& taxRate, double& grossPay, string& empName)
{
	getline(input, empName, '#');
	input >> hourRate;
	input >> workHours;
	input >> taxRate;
        input.ignore(); // This seems to fix the problem. Don't know why.
}
Thanks vin! That totally worked.
Topic archived. No new replies allowed.