Hi, I am trying to undertake an exercise in which a payroll file is generated. Unfortunately, I seem to be having problems with respect to passing values to functions that calculate pay for various types of employees and tax rates. The code compiles and runs, but generates zeroes for the various calculations that take place in the functions. Any advice or help would be deeply appreciated.
I have included a file, as that might make my code easier to read that the pasted code below. Thanks again, kindly.
#include<iostream>
#include<fstream>
#include<iomanip>
#include<math.h>
#include<string>
using namespace std;
const int Count = 1, Size1 = 10, Size2 = 15;
const float stateTaxRate = 0.05;
const float fedTaxRate = 0.15;
const float unionFees = 0.02;
float calcManagerGross(float);
float calcLevelOneGross(float);
float calcLevelTwoGross(float);
float calcAllOthersGross(float);
float calcStateTax(float);
float calcFederalTax(float);
float calcUnionFees(float);
float calcNet(float);
void displayResults(void);
typedef char List_A[Count][Size1];
typedef char List_B[Count][Size2];
int i,j;
float hours[Count], rate[Count], net[Count], taxAmt[Count], gross[Count], overTime[Count], stateTaxAmt[Count], fedTaxAmt[Count], unionFeeAmt[Count];
float managerGross, levelOneGross, levelTwoGross, allOthersGross, stateTax, fedTax, employeeNet;
List_A First_Name;
string middleInitial;
List_B Last_Name;
List_B ID_Num;
char selection;
int main()
{
ofstream myfile;
myfile.open("payrecord.txt");
for(i=0; i<Count; i++)
{
cout << "Please enter the employee's first name: " << endl;
cin >> First_Name[i];
cout << "Please enter the employee's middle initial: " << endl;
cin >> middleInitial[i];
cout << "Please enter the employee's last name: " << endl;
cin >> Last_Name[i];
cout << "Please enter the employee ID number: " << endl;
cin >> ID_Num[i];
cout << "Please enter the employee's compensation level: " << endl;
cout << '\t' << "A. Manager" << endl;
cout << '\t' << "B. Work Level I" << endl;
cout << '\t' << "C. Work Level II" << endl;
cout << '\t' << "D. All others" << endl;
cin >> selection;
switch(selection)
{
case 'A':
cout << "Please enter the total hours of *OVERTIME* that employee worked. Company " << endl;
cout << "policy dictates that the minimum weekly hours is 40 and the maximum is" << endl;
cout << "60 for compensation purposes, so please enter only hours of overtime." << endl;
cin >> overTime[i];
if(overTime[i]<0 || overTime[i]>20)
{
do
{
cout << "You can only enter between 0 and 20 hours of overtime per week." << endl;
cin >> overTime[i];
}
while(overTime[i]<0 || overTime[i]>20);
}
cout << "Please enter the employee's hourly rate: " << endl;
cin >> rate[i];
if(rate[i]<=0)
{
do
{
cout << "Please enter a positive, nonzero number." << endl;
cin >> rate[i];
}
while(rate[i]<=0);
}
gross[i]=calcManagerGross(managerGross);
break;
case 'B':
cout << "Please enter the total hours of *OVERTIME* that employee worked. Company " << endl;
cout << "policy dictates that the minimum weekly hours is 40 and the maximum is" << endl;
cout << "60 for compensation purposes, so please enter only hours of overtime." << endl;
cin >> overTime[i];
if(overTime[i]<0 || overTime[i]>20)
{
do
{
cout << "You can only enter between 0 and 20 hours of overtime per week." << endl;
cin >> overTime[i];
}
while(overTime[i]<0 || overTime[i]>20);
}
cout << "Please enter the employee's hourly rate: " << endl;
cin >> rate[i];
if(rate[i]<=0)
{
do
{
cout << "Please enter a positive, nonzero number." << endl;
cin >> rate[i];
}
while(rate[i]<=0);
}
gross[i]=calcLevelOneGross(levelOneGross);
break;
case 'C':
cout << "Please enter the total hours of *OVERTIME* that employee worked. Company " << endl;
cout << "policy dictates that the minimum weekly hours is 40 and the maximum is" << endl;
cout << "60 for compensation purposes, so please enter only hours of overtime." << endl;
cin >> overTime[i];
if(overTime[i]<0 || overTime[i]>20)
{
do
{
cout << "You can only enter between 0 and 20 hours of overtime per week." << endl;
cin >> overTime[i];
}
while(overTime[i]<0 || overTime[i]>20);
}
cout << "Please enter the employee's hourly rate: " << endl;
cin >> rate[i];
if(rate[i]<=0)
{
do
{
cout << "Please enter a positive, nonzero number." << endl;
cin >> rate[i];
}
while(rate[i]<=0);
}
gross[i]=calcLevelTwoGross(levelTwoGross);
break;
case 'D':
cout << "Please enter the total hours of *OVERTIME* that employee worked. Company " << endl;
cout << "policy dictates that the minimum weekly hours is 40 and the maximum is" << endl;
cout << "60 for compensation purposes, so please enter only hours of overtime." << endl;
cin >> overTime[i];
if(overTime[i]<0 || overTime[i]>20)
{
do
{
cout << "You can only enter between 0 and 20 hours of overtime per week." << endl;
cin >> overTime[i];
}
while(overTime[i]<0 || overTime[i]>20);
}
cout << "Please enter the employee's hourly rate: " << endl;
cin >> rate[i];
if(rate[i]<=0)
{
do
{
cout << "Please enter a positive, nonzero number." << endl;
cin >> rate[i];
}
while(rate[i]<=0);
}
gross[i]=calcAllOthersGross(allOthersGross);
break;
default:
do
{
cout << "Please enter one of the above menu choices." << endl;
cin >> selection;
}
while((selection != 'A') && (selection !='B') && (selection != 'C') && (selection != 'D'));
} // end of switch structure
cout << "Your gross is " << gross << endl;
stateTaxAmt[i] = calcStateTax(stateTax);
fedTaxAmt[i] = calcFederalTax(fedTax);
unionFeeAmt[i] = calcUnionFees(unionFees);
net[i] = calcNet(employeeNet);
}
displayResults();
myfile.close();
system("pause");
return 0;
} // end of main
//function CALC MANAGER GROSS
float calcManagerGross(float)
{
float rate, gross;
gross = 40*(rate);
return(gross);
}
//function CALC LEVEL ONE GROSS
float calcLevelOneGross(float)
{
float overTime, rate, gross;
gross = (overTime*(1.5*rate))+(40*rate);
return(gross);
}
//function CALC LEVEL TWO GROSS
float calcLevelTwoGross(float)
{
float overTime, rate, gross;
if(overTime<=15)
{
gross = (overTime*(1.5*rate)+(40*rate));
}
else
{
gross = (15*1.5*(rate)+(40*rate));
}
return(gross);
}
//function CALC OTHERS GROSS
float calcAllOthersGross(float)
{
float overTime, rate, gross;
if(overTime<=10)
{
gross = (overTime*(1.5*rate)+(40*rate));
}
else
{
gross = (10*1.5*(rate)+(40*rate));
}
return(gross);
}
//function CALC STATE TAX
float calcStateTax(float stateTax)
{
float gross, stateTaxAmt;
stateTaxAmt = gross - (gross*stateTaxRate);
return(stateTaxAmt);
}
//function CALC FED TAX
float calcFederalTax(float fedTax)
{
float gross, fedTaxAmt;
fedTaxAmt = gross - (gross*fedTaxRate);
return(fedTaxAmt);
}
//function CALC UNION FEES
float calcUnionFees(float unionFee)
{
float unionFeeAmt, gross;
unionFeeAmt = gross - (gross*unionFees);
return(unionFeeAmt);
}
//function CALC NET
float calcNet(float totalNet)
{
float net, gross, stateTaxAmt, fedTaxAmt, unionFeesAmt;
net = gross - stateTaxAmt - fedTaxAmt - unionFeesAmt;
return(net);
}
//function DISPLAY RESULTS
void displayResults(void)
{
for(j=0; j<Count; j++)
{
cout << First_Name[j] << '\t' << setw(1) << middleInitial[j] << '\t' << setw(1) << Last_Name[j] << '\t' << setw(1) << ID_Num[j] << '\t' << setw(1) << setprecision(2) << fixed << rate[j] << '\t' << setw(1) << setprecision(2) << fixed << overTime[j] << '\t' << setw(1) << setprecision(2) << fixed << "$" << gross[j] << '\t' << setw(1) << setprecision(2) << fixed << "$" << stateTaxAmt[j] << '\t' << setw(1) << setprecision(2) << fixed << "$" << fedTaxAmt[j] << '\t' << setw(1) << setprecision(2) << fixed << "$" << unionFeeAmt[j] << '\t' << setw(1) << setprecision(2) << fixed << "$" << net[j] << endl;
}
}