Payroll Program Time-and-a-half Struggle

I am pretty new to programming and am attempting to write my first program in one of my college classes. I have scoured the internet and I am not really sure where I am going wrong. I am close to solving it, but just can't quite get it to go through. When I execute the code:

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
//***************************************************
//Determine gross pay for a four-week period based
//on hourly rate and number of hours worked each week
// with any hours over 40 being paid time-and-a-half
//***************************************************

#include <iostream>

using namespace std;

float calcPay(float payRate, float hoursArray[] ); //Function prototype declares 'void' meaning an empty set of values
                                                   //and also specifies the type of arguments
float payPeriod (float arr[]);


int main()
{
    float payRate = 0.0;                   //Employee pay rate
    float hoursWeek[4] = {0.0};            //Hours worked in week
    int employeeID;                      //Employee ID
    float grossPay = 0.0;
    float MAX_HOURS = 40.0;
    float OVERTIME = 1.5;


    cout << " Enter employee ID number: ";
    cin >> employeeID;

    cout << " Enter hourly pay rate: ";
    cin >> payRate;


        cout << " Gross pay for the month is: " << calcPay(payRate, hoursWeek) << endl;

        cout << " The hours this pay period are: " << payPeriod(hoursWeek) << endl;

        return 0;
}

float calcPay(float payRate, float hoursArray[])
   {
       float grossPay = 0;
       float MAX_HOURS = 40.0;
       float OVERTIME = 1.5;
       float hoursWeek[4] = {0.0};

   for (int i=0; i<4; i++)
        {
             cout << " Enter hours worked in week " << i+1 << ": ";
             cin >> hoursWeek[i];

   if (hoursWeek[i] > MAX_HOURS)
   {
      grossPay = (MAX_HOURS * payRate) + (hoursWeek[i]-MAX_HOURS) *payRate *OVERTIME;
   }
      else
      {
         grossPay = hoursWeek[i] * payRate;
      }

      for(int i=0;i<4;i++)
		{
			grossPay+=payRate*hoursWeek[i];
		}

   return grossPay;
        }
   }


float payPeriod(float arr[])
{
	float total=0;
	for(int i=0;i<4;i++)
	total+=arr[i];
	return total;

}


This is by no means beautiful in organization as I am still trying to get the hang of proper etiquette.

I don't have any errors, but it is not doing what I want it to. What I want it to do and the goal is to calculate the gross pay for each week (accounting for overtime) and then total them together. 40 hours is straight pay and time-and-a-half is 1.5. I had the code correct to where I was able to enter the pay, get a prompt for four weeks hours, the total gross pay and hours that pay period. I switched things up too much that now I can't get back to that OR get it to calculate correctly.

Now, this code outputs double time and I am not sure how that is happening either.

I thought using an array would be a good idea, but I don't know if it is anymore. I am pretty inexperienced and still wrapping my brain around the abstract stuff.

Any insight would be appreciated!

Thanks, Elyseis
Topic archived. No new replies allowed.