how to read each line of a file

I have this program that takes employee information and outputs their paystub to a file. My code is working properly but it only works for the first line. How can I read and output each line??

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

using namespace std;

ifstream infile;
ofstream outfile, errorfile;

void GetData (string& firstname, string& lastname, double& wage, double& hours, int& exemptions, char& maritalstatus);
double Gross (double wage, double hours);
double FITW (double Gross, int exemptions, char maritalstatus);
double FICA (double Gross);
void SendData (string firstname, string lastname, double hours, double wage, double Gross, double FICA, double FITW, double netpay);

int main ()
{
	infile.open("employee.txt");
	string firstname, lastname;
	double wage, hours, fitw, grosspay, ficatax, netpay;
	char maritalstatus;
	int exemptions;
	GetData (firstname, lastname, wage, hours, exemptions, maritalstatus);
	infile.close();
	
	grosspay = Gross (hours, wage);
	ficatax = FICA (grosspay);	
	fitw = FITW (grosspay, exemptions, maritalstatus);
	netpay = grosspay - ficatax - fitw;
	SendData (firstname, lastname, hours, wage, grosspay, ficatax, fitw, netpay);
}

void GetData (string& firstname, string& lastname, double& wage, double& hours, int& exemptions, char& maritalstatus)
{
	infile >> firstname >> lastname >> wage >> hours >> exemptions >> maritalstatus;
}

double Gross(double wage, double hours)
{	
	return (wage*hours);
}

double FITW (double Gross, int exemptions, char maritalstatus)
{
	double AWIncome;
	AWIncome=Gross-(exemptions*73.08);
	if ((AWIncome<=721) && (maritalstatus=='S' || 's'))
		return (0);
	else if ((AWIncome>721 && AWIncome<=7510) && (maritalstatus=='S' || 's'))
		return ((AWIncome-721)*0.28+93.60);
	else
		return ((AWIncome-7510)*0.35+2167.16);


	if ((AWIncome<=1515) && (maritalstatus=='M' || 'm'))
		return (0);
	else if ((AWIncome>1515 && AWIncome<=7624) && (maritalstatus=='M' || 'm'))
		return ((AWIncome-1515)*0.15+187.15);
	else
		return ((AWIncome-7624)*0.30+2020.42);
}

double FICA (double Gross)
{
	const double FICAtax=0.0565;
	return (Gross*FICAtax);
}


void SendData (string firstname, string lastname, double hours, double wage, double Gross, double FICA, double FITW, double netpay)
{
	outfile.open("payroll.txt");
	outfile <<fixed<< showpoint << setprecision(2);
	outfile << "***********************************************" <<endl;
	outfile <<"Payroll for: " << firstname << " " << lastname << endl;
	outfile <<"Hours worked: " << hours << endl;
	outfile <<"Hourly wage: " << wage << endl;
	outfile <<"Gross pay: " << Gross << endl;
	outfile <<"FICA tax: " << FICA << endl;
	outfile <<"Federal Income Tax Witheld: " << FITW << endl;
	outfile <<"Your net income is: " << netpay << endl;
	outfile <<"***********************************************" <<endl;
	outfile.close();
	return;
}


input looks like this
Al Clark 38 45.5 4 M
Joyce Itin 120 77 3 M
Vahid Hamidi 15 25 3 M
Melody Jung 27 60.6 1 M
Joahn Garcia -25 -3 -3 M
Vera Moroz 23 72 3 N
Robert Innes 19.85 40 1 S
Mark Armstrong -25 23 5 M
Ashton Williams 15 15.69 -6 S
Angela Klein 0 54.32 6 S
Jerry Smith 168.5 36.5 2 S
Leslie McHenry 68 95.63 1 S
Morgan Stock 72 99 2 S
Nick Lee 15 5 1 S
Mary Jones 45 75.36 2 S


output should look like this except it should include all employee information

***********************************************
Payroll for: Mary Jones
Hours worked: 75.36
Hourly wage: 45.00
Gross pay: 3391.20
FICA tax: 191.60
Federal Income Tax Witheld: 800.33
Your net income is: 2399.27
***********************************************
Last edited on
Topic archived. No new replies allowed.