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:

 ``123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778`` ``````//*************************************************** //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 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.