### Get the program to apply time and a half to all weeks.

In my code, I am trying to enter four weeks worth of hours and get the weekly total and then total all four weeks for a gross pay for the month. My code applies the calcPay function to only the last week. How do I get it to apply it to the rest of the weeks?

 ``12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849`` ``````//*************************************************** //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 void calcPay (double, double, double&); //Declaring a function before using & pointer to return const float MAX_HOURS = 40.0; const float OVERTIME = 1.5; using namespace std; int main() { double payRate = 0.0; int weeks = 4; double hours = 0.0; double wages = 0.0; cout << "Enter pay rate amount: \$"; cin >> payRate; for(int i=0; i> hours; } calcPay(payRate, hours, wages); cout <<"Wages earned this month are " << wages << "."; return 0; } void calcPay (double payRate, double hours, double& wages) { if (hours > MAX_HOURS) { wages = MAX_HOURS * payRate + (hours - MAX_HOURS) * OVERTIME * payRate; } else { wages = hours * payRate; } return; }``````
Last edited on
At lines 25-29 you have a loop where the hours are entered. Inside that loop, just after getting the hours, call the `calcPay()` function.

But that won't be enough by itself. Each time it is called, it will generate a resulting value of `wages`.

I'm not sure what you want to do next. Perhaps print out the wages for each week inside that same loop. Or perhaps add it to a grand total and then after the loop is completed, print out the total for all four weeks. Or maybe both.
Last edited on

### Forum

• 629832435 2018-04-20
• 4254782434 2018-04-20
• 7642392433 2018-04-20
• 4201592432 2018-04-20
• 1221362431 2018-04-20
• 5455692430 2018-04-20
• 8345962429 2018-04-20
• 7297372428 2018-04-20
• 4929522427 2018-04-20
• 1938132426 2018-04-20
• 2267862425 2018-04-20
• 6177082424 2018-04-20
• 838232423 2018-04-20
• 4694502422 2018-04-20
• 6512882421 2018-04-19
• 4659652420 2018-04-19
• 2967832419 2018-04-19
• 8339042418 2018-04-19
• 8147112417 2018-04-19
• 2774752416 2018-04-19