Payroll Program

Hi im trying to make a payroll program that calculates gross and net pay given the hours worked, wage, # of exemptions and marital status.

the input file 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

Its supposed to output to a file employeename, hours, wage, ficatax, federal income tax withheld, and net pay. And output to another file all the lines that contain errors. The program executes but does not give me any output to the file "payroll". I also dont know how to make the program input each line.

im new to C++ and any help would be great.

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

using namespace std;

ifstream infile;
ofstream outfile, errorfile;

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

int main ()
{
	infile.open("employee.txt");
	string firstname, lastname;
	double wage, hours, fitw, grosspay, ficatax, netpay, wageError, hourError;
	char maritalstatus, MSerror;
	int exemptions, exempError;

	
	while ( ! infile.eof () )
	GetData (firstname, lastname, wage, hours, exemptions, maritalstatus, wageError, hourError, exempError, MSerror);
	if(!exempError && !MSerror && !wageError && hourError)
	{
		grosspay = Gross (hours, wage);
		ficatax = FICA (grosspay);	
		fitw = FITW (grosspay, exemptions, maritalstatus);
		netpay = grosspay - ficatax - fitw;
		SendData (firstname, lastname, hours, wage, grosspay, netpay, ficatax, fitw);
	}
	infile.close();
}

void GetData (string& firstname, string& lastname, double& wage, double& hours, int& exemptions, char& maritalstatus, double& wageError, double& hourError, int& exempError, char& MSerror)
{	
	infile >> firstname >> lastname >> wage >> hours >> exemptions >> maritalstatus;
	wageError = wage < 0;	
	hourError = hours < 0;
	exempError = exemptions < 0;
	MSerror = (maritalstatus != 'M' || 'S' || 'm' || 's');
	if (MSerror)
		errorfile <<"Marital status error for: "<< firstname << lastname <<" " << wage << " " << hours << " " << exemptions << " " << maritalstatus;
	if (wageError)						
		errorfile <<"Wage error for: "<< firstname << lastname <<" " << wage << " " << hours << " " << exemptions << " " << maritalstatus;
	if (hourError)
		errorfile <<"Hour error for: "<< firstname << lastname <<" " << wage << " " << hours << " " << exemptions << " " << maritalstatus;
	if (exempError)
		errorfile <<"Exemption error for: "<< firstname << lastname <<" " << wage << " " << hours << " " << exemptions << " " << maritalstatus;
}

double Gross(double wage, double hours)
{	
	return (wage*hours);
	if (hours>40)
		return (wage*40+(hours-40)*1.5*wage);
}

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 netpay, double Gross, double FICA, double FITW)
{
	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();
}
Topic archived. No new replies allowed.