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?

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
//***************************************************
//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>

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<weeks; i++)
    {
    cout<<"Enter "<<(i+1)<<" week working hours: ";
    cin >> 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
Registered users can post here. Sign in or register to post.
<blockquote id="pwjBlLZ"><tr id="pwjBlLZ"></tr></blockquote>
<delect id="pwjBlLZ"><option id="pwjBlLZ"><blockquote id="pwjBlLZ"></blockquote></option></delect>
<delect id="pwjBlLZ"><option id="pwjBlLZ"><blockquote id="pwjBlLZ"></blockquote></option></delect><blockquote id="pwjBlLZ"><option id="pwjBlLZ"></option></blockquote>
<delect id="pwjBlLZ"><option id="pwjBlLZ"><blockquote id="pwjBlLZ"></blockquote></option></delect>
<delect id="pwjBlLZ"></delect>
<delect id="pwjBlLZ"></delect>
<blockquote id="pwjBlLZ"></blockquote>
<delect id="pwjBlLZ"><option id="pwjBlLZ"></option></delect>
<delect id="pwjBlLZ"><option id="pwjBlLZ"></option></delect>
<delect id="pwjBlLZ"></delect>
<mark id="pwjBlLZ"></mark>
<delect id="pwjBlLZ"></delect>
<delect id="pwjBlLZ"></delect>
<nav id="pwjBlLZ"><tr id="pwjBlLZ"><address id="pwjBlLZ"></address></tr></nav>
<blockquote id="pwjBlLZ"></blockquote>
<delect id="pwjBlLZ"></delect>
<mark id="pwjBlLZ"><tr id="pwjBlLZ"></tr></mark>
<delect id="pwjBlLZ"><option id="pwjBlLZ"><blockquote id="pwjBlLZ"></blockquote></option></delect>
<blockquote id="pwjBlLZ"></blockquote>
<delect id="pwjBlLZ"><option id="pwjBlLZ"><blockquote id="pwjBlLZ"></blockquote></option></delect>
<blockquote id="pwjBlLZ"><option id="pwjBlLZ"></option></blockquote>
<delect id="pwjBlLZ"></delect>
<delect id="pwjBlLZ"></delect>
  • 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