Help with Gross pay

I need help with this when i do the problem for homework everything works find except the total gross pay just doesnt add up right for some reason it adds up all the gross pays but it doesnt do the math right

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
# include <iostream>  
# include <iomanip>
# include <cmath>  

using namespace std;

//function prototypes  
double getGrossPay(double regPay, double ovrTimePay, double hrsWrk, double payRate, double grossPay);
double getTotalGrossPay(double grossPay, int acc, double totalGrossPay);

int main()
{

	//declare variables  
	double hrsWrk = 0.0;
	double payRate = 0.0;
	double regPay = 0.0;
	double grossPay = 0.0;
	double totalGrossPay = 0.0;
	double ovrTimePay = 0.0;
	int    acc = 0;
	char sentinel = ' ';

	//priming the loop  
	cout << "Do you have hours to enter? Y/N(N to stop):";
	cin >> sentinel;

	while (toupper(sentinel) == 'Y')
	{
		cout << "Enter hours worked:" << endl;
		cin >> hrsWrk;
		cout << "Enter pay rate:" << endl;
		cin >> payRate;

		//call function for indiv. grossPay
		grossPay = getGrossPay(regPay, ovrTimePay, hrsWrk, payRate, grossPay);

		//Display information  
		cout << fixed << setprecision(2);
		cout << "grossPay:$" << grossPay << endl;
		cout << "Do you have any more hours to enter? (Y/N):" << endl;
		cin >> sentinel;
	} //end while

	  //call function for total gross pay  
	totalGrossPay = getTotalGrossPay(grossPay, acc, totalGrossPay);

	cout << "totalGrossPay:$" << totalGrossPay << endl;
	system("pause");
	return 0;
}

//function definitions  
double getGrossPay(double regPay, double ovrTimePay, double hrsWrk, double payRate, double grossPay)
{
	//calculates and returns the gross Pay 
	if (hrsWrk <= 40)
	{
		regPay = hrsWrk * payRate;
		grossPay = regPay + ovrTimePay;
	}
	else
	{
		(hrsWrk > 40);
		ovrTimePay = (hrsWrk - 40) * (payRate * 1.5) + (40 * payRate);
		grossPay = ovrTimePay + regPay;
	}// end if
	return grossPay;
}//end of function 

 // calculates the total gross pay //issue is somewhere in here
double getTotalGrossPay(double grossPay, int acc, double totalGrossPay)
{
	acc += grossPay;
	totalGrossPay = acc + grossPay;
	return totalGrossPay;
} //end of function 
I don't understand the intention of function getTotalGrossPay(). I think I understand totalGrossPay. But what is acc ?

It seems like there are lots of parameters being passed to the function(s) which are not needed.

Keep things simple, only pass what is necessary.
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
#include <iostream>  
#include <iomanip>
#include <cmath>  

using namespace std;

double getGrossPay(double hrsWrk, double payRate);

int main()
{
    // declare variables  
    double hrsWrk        = 0.0;
    double payRate       = 0.0;
    double totalGrossPay = 0.0;

    char   sentinel      = ' ';

    // prime the loop  
    cout << "Do you have hours to enter? Y/N  (N to stop): ";
    cin >> sentinel;

    while (toupper(sentinel) == 'Y')
    {
        cout << "Enter hours worked:\n";
        cin  >> hrsWrk;
        cout << "Enter pay rate:\n";
        cin  >> payRate;

        // call function for individual gross pay
        double grossPay = getGrossPay(hrsWrk, payRate);
        totalGrossPay += grossPay;
        

        // Display information  
        cout << fixed << setprecision(2);
        cout << "grossPay:$" << grossPay << endl;
        cout << "Do you have any more hours to enter? (Y/N):" << endl;
        cin  >> sentinel;
    }


    cout << "totalGrossPay:$" << totalGrossPay << endl;
}

double getGrossPay(double hrsWrk, double payRate)
{
    // calculates and returns the gross Pay 

    double grossPay = 0.0;
    
    if (hrsWrk <= 40)
    {
        grossPay = hrsWrk * payRate;
    }
    else
    {
        grossPay = (hrsWrk - 40) * (payRate * 1.5) + (40 * payRate);
    }
    
    return grossPay;
}

how do i pause it after it shows the Total gross pay??
Oh, sorry about that. You could put back the pause you had in the original version.

I removed it because the IDE I use keeps the console open automatically.
See also
http://www.cplusplus.com/forum/beginner/1988/
im also interested in how a void function would work in this is there any way you could show me how to use a void function in this problem so i can get the hang of that also?
There's an example in the tutorial:
http://www.cplusplus.com/doc/tutorial/functions/
1
2
3
4
void printmessage (void)
{
  cout << "I'm a function!";
}

However I don't see how that would be useful in the current program.

Perhaps what you are really interested in is how to pass values by reference? See Arguments passed by value and by reference in the same tutorial.
The example given is the function duplicate().

Perhaps you'd like to try some example for yourself and if you have any problems, post again so we can take a look and try to resolve any issues.
Topic archived. No new replies allowed.