corrupt values

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);

int main()
{
int numTax, empid[MAX_EMPLOYEES], hours[MAX_EMPLOYEES], numEmp,
size;
float taxable[MAX_TAXTABLE], taxrate[MAX_TAXTABLE],
hourlyrate[MAX_TAXTABLE], wages, rate, netpay;
GetTaxTable(taxable, taxrate, numTax);
GetEmpHours(empid, hours, hourlyrate, numEmp);
PrintHeader(numEmp);
ProcessPayroll(empid, hours, hourlyrate, numEmp, taxable, taxrate, numTax);
return 0;
}

//---------------------------------------------------------------------
// 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;
}

Input Sample
5
1000 .035
2000 .055
3000 .072
4000 .085
5000 .1
17
1001 43 51.0
1002 34 10.5
1003 56 32.0
1004 41 80.5
1005 43 40.0
1006 0 12.0
1007 44 88.5
1008 40 55.5
1009 -8 60.0
1010 70 88.5
1011 49 60.0
1012 18 20.0
1013 55 88.5
1014 21 5.0
1015 65 34.5
1016 35 08.5
1017 40 20.5

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:

Employee Payroll with 17 entries.

EmpID Gross Pay Tax Rate Net Pay
------ --------- --------- ---------
1001 2269.50 7.20% 2106.10
1002 357.00 3.50% 344.51
1003 2048.00 7.20% 1900.54
1004 3340.75 8.50% 3056.79
1005 1780.00 5.50% 1682.10
1006 Zero or negative hours! Unable to process!!
1007 4071.00 10.00% 3663.90
1008 2220.00 7.20% 2060.16
1009 Zero or negative hours! Unable to process!!
1010 Abnormal overtime hours! Unable to process!!
1011 3210.00 8.50% 2937.15
1012 360.00 3.50% 347.40
1013 5531.25 12.00% 4867.50
1014 105.00 3.50% 101.32
1015 Abnormal overtime hours! Unable to process!!
1016 297.50 3.50% 287.09
1017 820.00 3.50% 791.30
------ --------- --------- ---------
Total gross pay: $ 26410.00
[quote]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.

const int MAX_TAXTABLE = 5;[quote]

Maybe you should look to the places where MAX_TAXTABLE is used.
durp. Thank you.
Topic archived. No new replies allowed.