Please Note: I am advised to use arrays, functions, parameter passing to achieve my goal.
Another calculator-program student in need of help...How many of these have you all seen? In all seriousness, I need to use functions and parameter passing to create 4 employees, and then calculate the total gross pay, the total federal tax, the total state tax and the total net pay of all four of the employees. So far, I've been able to make a program that does this for only 1 employee. My question is in regards to: how do I expand this code to record 4 employee records and then tally the aforementioned totals? I was thinking of putting it inside a for-loop starting at i<4, but I'm not exactly sure. My biggest concern is using parameter passing because I need to use parameter passing. Here is the code:
#include<iostream>
#include<string>
#include<iomanip>
using namespace std;
string employeeName;
float overtime;
float grossPay;
float hoursWorked;
float hourlyRate;
float statetaxOwed;
float statetaxRate;
float fedtaxOwed;
float fedtaxRate;
float netPay;
int main()
{
cout << "Please enter the Employee's Name: ";
getline(cin, employeeName);
cout << "Please enter your hours worked: ";
cin >> hoursWorked;
cout << "Please enter your hourly rate: ";
cin >> hourlyRate;
cout << "Please enter the Federal Tax Rate: ";
cin >> fedtaxRate;
cout << "Please enter the State Tax Rate: ";
cin >> statetaxRate;
if (hoursWorked>40){
hoursWorked = ((hoursWorked-40) * (1.5)) + 40;
}
else {
hoursWorked=hoursWorked;
}
grossPay = hoursWorked * hourlyRate;
fedtaxOwed = grossPay * (fedtaxRate/100);
statetaxOwed = grossPay * (statetaxRate/100);
netPay = (grossPay-fedtaxOwed- statetaxOwed);
cout << setprecision(2) << showpoint << fixed;
cout << "\nThe employee's name is: " << employeeName << endl;
cout << "The Gross Pay is: $" << grossPay << endl;
cout << "The Federal Taxes Owed is: $" << fedtaxOwed << endl;
cout << "The State Taxes Owed is: $" << statetaxOwed << endl;
cout << "The Net Pay for the Employee is: $" << netPay << endl;
}
Ideally the flow would operate like this:
Input: Employee 1 Name, Hours Worked, Hourly Rate, Fed Tax Rate, and State Tax Rate
Input: Employee 2 Name, Hours Worked, Hourly Rate, Fed Tax Rate, and State Tax Rate
Input: Employee 3 Name, Hours Worked, Hourly Rate, Fed Tax Rate, and State Tax Rate
Input: Employee 4 Name, Hours Worked, Hourly Rate, Fed Tax Rate, and State Tax Rate
{C A L C U L A T E}
Print: Employee 1 Name, Gross Pay, Fed Taxes Owed, State Taxes Owed, Net Pay
Print: Employee 2 Name, Gross Pay, Fed Taxes Owed, State Taxes Owed, Net Pay
Print: Employee 3 Name, Gross Pay, Fed Taxes Owed, State Taxes Owed, Net Pay
Print: Employee 4 Name, Gross Pay, Fed Taxes Owed, State Taxes Owed, Net Pay
Print: Total Gross Pay, Total Federal Taxes Owed, Total State Taxes Owed, Total Net Pay [THIS IS ACROSS ALL FOUR EMPLOYEES]
Print: Calculated Overtime Pay Total and Print # of Employees that worked overtime