Hello. looking for some help getting over this wall. When I input a list of employees (17 of them) with their id #, hours worked, and pay rate. I got an error message saying, "taxable is corrupted". But When size of the employees list is between 1 and 5. It works fine. Not until when the employe list size becomes 6 (id# 1006) and greater. That's when the errors starts to happen. I'm suppose to test if employee hours is 0 and if it is a negative value, and cout a error message. I did have them in my ComputeWages function, but it still compute the calculation followed by the error message( those test statements are no longer there). Below is my program followed by the list of inputs and the results. If someone can give me a hint on how to fix this problem would be great.
#include <iostream>
#include <iomanip>
#include <string>
using namespace std;
const int MAX_TAXTABLE = 5;
const int MAX_EMPLOYEES = 25;
void GetTaxTable(float taxable[], float taxrate[], int & numTax);
void GetEmpHours(int empid[], int hours[], float hourlyrate[],
int & numEmp);
void PrintHeader(int numEmp);
bool OverHoursLimit(int hours);
int FindTaxLevel(float wages, const float taxable[], int size);
float ComputeWages(int hours, float hourlyrate);
void PrintEmpWages(int empid, float wages, float rate, float netpay);
void ProcessPayroll(const int empid[], const int hours[],
const float hourlyrate[], int numEmp,
const float taxable[], const float taxrate[],
int numTax);
//---------------------------------------------------------------------
// This function reads the tax table and stores it in a pair of
// parallel arrays. The function should read the size of the table
// first, and then read the wage levels and tax rates.
// Params: TODO
//---------------------------------------------------------------------
void GetTaxTable(float taxable[], float taxrate[], int & numTax)
{
cin >> numTax;
for (int i = 0; i < numTax; i++)
cin >> taxable[i] >> taxrate[i];
}
//---------------------------------------------------------------------
// This function reads the log table of employees and stores the table
// in three parallel arrays. The function should read the size of the
// table first, and then read the employee IDs, work hours, and hourly
// rates.
// Params: TODO
//---------------------------------------------------------------------
void GetEmpHours(int empid[], int hours[], float hourlyrate[],
int & numEmp)
{
cin >> numEmp;
for (int i = 0; i < numEmp; i++)
cin >> empid[i] >> hours[i] >> hourlyrate[i];
}
//---------------------------------------------------------------------
// This function prints out the header of the resulting payroll table
// given the number of entries in the table.
// Params: TODO
//---------------------------------------------------------------------
void PrintHeader(int numEmp)
{
cout << "Enter the number of levels for the tax table: Enter "
<< "taxable wages and tax rates:" << endl << "Enter the number "
<< "of employees to process: Enter employee ID, hours and hourly"
<< " rate:" << endl << endl << "Employee Payroll with " << numEmp
<< " entries." << endl << endl;
cout << " EmpID Gross Pay Tax Rate Net Pay" << endl << "------ "
<< "--------- --------- ---------" << endl;
}
//---------------------------------------------------------------------
// This function processes the data stored in the parallel arrays,
// computes the wages and tax withheld, and prints out the results.
// Params: TODO
//---------------------------------------------------------------------
void ProcessPayroll(const int empid[], const int hours[],
const float hourlyrate[], int numEmp,
const float taxable[], const float taxrate[],
int numTax)
{
int hour, emp, txl = 0;
float rate = 0, wage = 0, txr = 0, net = 0, pay = 0;
for (int i = 0; i < numEmp; i++)
{
emp = empid[i];
hour = hours[i];
rate = hourlyrate[i];
wage = ComputeWages(hour, rate);
txl = FindTaxLevel(wage, taxable, numTax);
txr = taxrate[txl];
net = wage * txr;
pay = wage - net;
PrintEmpWages(emp, wage, txr, pay);
}
}
//---------------------------------------------------------------------
// This function determines whether a given number of work hours
// exceeds the limit of overtime hours.
// Params: TODO
//---------------------------------------------------------------------
bool OverHoursLimit(int hours)
{
if (hours > 60)
return true;
else
return false;
}
//---------------------------------------------------------------------
// Given the wages, this function finds and returns the index of the
// associated tax rate in the tax table. It returns a -1 if the wages
// exceed the maximum tax level.
// Params: TODO
//---------------------------------------------------------------------
int FindTaxLevel(float wages, const float taxable[], int size)
{
if (wages <= taxable[size - 1])
{
for (int i = 0; i < size; i++)
{
if (wages <= taxable[i])
return i;
}
}
else
return -1;
}
//---------------------------------------------------------------------
// This function computes and returns the wages based on the hours
// worked and the hourly rate.
// Params: TODO
//---------------------------------------------------------------------
float ComputeWages(int hours, float hourlyrate)
{
float extra = 0, grosspay = 0;
if (hours > 40)
{
extra += hours - 40;
grosspay = ((hours - extra) * hourlyrate) + (extra *
(hourlyrate* 1.5));
}
else
grosspay = hours * hourlyrate;
return grosspay;
}
//---------------------------------------------------------------------
// This function prints out employee's ID, wages, tax rate, and the
// net pay.
// Params: TODO
//---------------------------------------------------------------------
void PrintEmpWages(int empid, float wages, float rate, float netpay)
{
cout << setw(6) << empid << setw(10) << wages << setw(10) << rate
<< setw(10) << netpay << endl;
}
Output Sample
Enter the number of levels for the tax table: Enter taxable wages and tax rates:
Enter the number of employees to process: Enter employee ID, hours and hourly rate: