Need advice on Payroll program it does not complie

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
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
// This is the Error I receive when I attempt to compile it I don't
// understand the error could someone help to just explain it to me
// or point me in the right direction.

//In function 'void ProcessPayRoll(const int*, const int*, const float*, int, //const float*, const float*, int)':
//102:16: warning: value computed is not used [-Wunused-value]
//102:16: warning: statement has no effect [-Wunused-value]
//104:39: error: invalid types 'const float*[float]' for array subscript

//------------------------------------------------------------------------
#include <iostream>
#include <string>
#include <iomanip>
using namespace std;

const int MAX_EMP = 25;
const int MAX_TAX = 5;
const float TAX_1000 = .035;
const float TAX_2000 = .06;
const float TAX_4000 = .085;
const float TAX_LUX = .12;
const int MAX_OVERTIME = 60;
const int MAX_NORMAL_HOURS = 40;

void GetTaxTable(float taxable[], float taxrate[], int& numTax);
void GetEmpHours(int empid[], int hours[], float hourlyrate[], int& numEmp);
void PrintHeader(int numEmp);
void ProcessPayRoll(const int empid[], const int hours[], 
                    const float hourlyrate[], int numEmp, 
                    const float taxable[], const float taxrate[],
                    int numTax);
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 GetTaxTable(float taxable[],float taxrate[], int& numTax)
{
   int length = numTax;
   for (int index = 0; index < length; index++)
   {
      cout << "Enter taxable wages and tax rates:" << endl;
      cin >> taxable[index];
      cin >> taxrate[index];
   }
}

void GetEmpHours(int empid[], int hours[], float hourlyrate[], int& numEmp)
{
   int size = numEmp;
   for (int k = 0; k < size; k++)
   {
      cout << "Enter employee ID, hours and hourly rate:" << endl;
      cin >> empid[k];
      cin >> hours[k];
      cin >> hourlyrate[k];
   }
}

// Specifically with this function it gives me the error as seen at the top.

void ProcessPayRoll(const int empid[], const int hours[], 
                    const float hourlyrate[], int numEmp, 
                    const float taxable[], const float taxrate[],
                    int numTax)
{
   int emplId = 0;
   int hoursEmp;
   float rateOfPay = 0;
   int wages = 0;
   float rateOfTax;
   float netPay = 0;
   float taxesTaken;
   float taxableWages = 0;
   for (int a = 0; a < numEmp; a++)
   {
      emplId = empid[a];
      hoursEmp = hours[a];
      rateOfPay = hourlyrate[a];
      wages = ComputeWages(hoursEmp, rateOfPay);
      taxable[a];
      taxableWages = FindTaxLevel(wages,taxable, numEmp);
      rateOfTax = taxrate[taxableWages];
      taxesTaken = wages * rateOfTax;
      netPay = wages - taxesTaken;
   }
   PrintEmpWages(emplId, wages, rateOfPay, netPay);
}

bool OverHoursLimit(int hours)
{
   if (hours > MAX_OVERTIME)
      return true;
   else 
      return false;
}

int FindTaxLevel(float wages, const float taxable[], int size)
{
   int i;
   for (i = 0; i < size; i++)
      if (taxable[i] <= wages)
         return i;
   return -1;
}

float CompeterWages(int hours[], float hourlyrate[])
{
   float grossPay = 0;
   int timeHours = 0;
   int timeLeft = 0;
   float rate;
   for (int h = 0; h < MAX_EMP; h++)
   {
      timeHours = hours[h];
      if (OverHoursLimit(timeHours) == true)
         cout << "Abnormal overtime hours! Unable to process!!" << endl;
      rate = hourlyrate[h];
      if (timeHours > MAX_NORMAL_HOURS)
      {
         timeLeft = timeHours - MAX_NORMAL_HOURS;
         grossPay = (timeLeft * rate) + (MAX_NORMAL_HOURS * rate);
      }
      else
         grossPay = timeHours * rate;
      return grossPay;
   }
   return 0.0;
}
Last edited on
....

Did you seriously just throw all of your code on our faces and ask for advice?

Firstly, please edit your post so all of your code is between code tags. The icon looks like this <> and its under the format section.

Second. Ask specific questions, about specific things. You having trouble with something? Is it not compiling? you getting errors? etc.
I am sorry about that I didn't finish the article before submitting. It made it seem very irresponsible and I do really apologize. Thank you for pointing that out.
Its all good mate, but please edit your post so I can take a look at the error, becuase right now its unreadable. Click edit, then there is a format section, mark all of your code and click the <> icon.
I'm having trouble marking my code on here
Its like marking anything anywhere... You just click on a spot and move your mouse to the end.

http://www.cplusplus.com/articles/jEywvCM9/
Thanks so much man!
In your ProcessPayRoll function. Everything in there is super weird.

1
2
3
4
5
6
7
8
9
10
11
12
 for (int a = 0; a < numEmp; a++)
   {
      emplId = empid[a];
      hoursEmp = hours[a];
      rateOfPay = hourlyrate[a];
      wages = ComputeWages(hoursEmp, rateOfPay);
      taxable[a];
      taxableWages = FindTaxLevel(wages,taxable, numEmp);
      rateOfTax = taxrate[taxableWages];
      taxesTaken = wages * rateOfTax;
      netPay = wages - taxesTaken;
   }


emplId = empid[a]; Whats happening here? You'er basically just putting the last element in the array inside of emplId, since its only a variable, it can only have one value.

Same with


1
2
hoursEmp = hours[a];
rateOfPay = hourlyrate[a];



This taxable[a]; Doesnt do anything.

taxableWages = FindTaxLevel(wages,taxable, numEmp); FindTaxLevel returns an integer, but taxableWages is a float?

wages = ComputeWages(hoursEmp, rateOfPay); CompugerWages is a float function, wages is an integer.

Last edited on
Okay, but do you see kind of what I am trying to accomplish? I am basically teaching this to myself, and I have no idea what I'm really doing here. I do apologize that this is so vague and not straightforward, but I'm so lost.
Honestly Im too tired to atm. And going through everything here is a big no. Feel Free to PM me your skype and I can help you out a bit better tomorrow when I got some real energy.
I PM'd you. Whenever your free I would appreciate your help
Topic archived. No new replies allowed.