Help With Code

This was the assignment presented to our class:

"Create a payroll program which reads in an employee's first name, last name, hours worked, and pay rate from a file into an array. Determine if the user has overtime or not. Deduct 10% taxes from the employee's gross pay. Then, output the employee's paycheck to a file. The output to file must be done within a function.

You need to format the output for 2 decimal places. Your input file should have at least 5 employees in it to make it interesting.

Finally, you need to create a separate function for determining which employee made the most money."

The code below meets all of the requirements except for those dealing with outputting the paycheck to a file, and determining which employee made the most money.

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

using namespace std;

void payRoll(string fName[], string lName[], double payRate[], double hoursWorked[], int count)
{
	double overTime, grossPay, netPay, tax = .10;


	for(int a=0;a<count;a++)
	{
		

		tax = .10;
		if(hoursWorked[a]>40)
		{
			overTime = payRate[a] * 1.5 * (hoursWorked[a] - 40);
			grossPay = overTime + 40 * payRate[a];
		}
		else
			grossPay = hoursWorked[a] * payRate[a];

		tax = grossPay * tax;
		netPay = grossPay - tax;
	
		cout << "First Name: " << fName[a] << endl;
		cout << "Last Name: " << lName[a] << endl;
		cout << "Pay rate: $" << payRate[a] << endl;
		cout << "Hours Worked: " << hoursWorked[a] << endl;
		cout << "Gross Pay: $" << grossPay << endl;
		cout << "Taxes Witheld: $" << tax << endl;
		cout << "Net Pay: $" << netPay << endl << endl << endl;
	}
}

int main()
{
	ifstream iFile;
	iFile.open("payroll.txt");

	const int n = 50;
	
	string fName[n], lName[n];
	int count=0; 
	double payRate[n], hoursWorked[n], overTime;
	double grossPay, netPay, tax = .10;

	cout << fixed << showpoint;
	cout << setprecision(2);

	while(!iFile.eof())
	{
		tax = .10;
		iFile >> fName[count];
		iFile >> lName[count];
		iFile >> payRate[count];
		iFile >> hoursWorked[count];
		count++;
	}
	payRoll(fName, lName, payRate, hoursWorked, count);

	
	system("pause");
	return 0;

}
Topic archived. No new replies allowed.