Multiple Value Returning Functions w/accumulator

Greetings,

I am new to C++ and have encountered a difficult (to me at least) homework problem.

The problem states: The payroll manager will enter the number of hours the employee worked and his or her pay rate. Employees working more than 40 hours should receive time and one-half for the hours over 40. Use a value-returning function to determine an employee’s gross pay. Use a different value-returning function to accumulate the total gross pay. The program should display the total gross pay only after the payroll manager has finished entering the data for all the employees. Use a sentinel value to end the program.

Here is what I have come up with so far. Any help on how to proceed would be appreciated. I am not looking for someone to just solve it for me, so explanations for modifications or additions/removals is highly valued.
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
#include <iostream>
#include <iomanip>

using namespace std;

//function prototypes
double getGrossPay(double hrs, double rate, double overtime, double regular);
double getTotalGrossPay(double totalGross);

int main()
{
	//declare variables
	double hours = 0.0;
	double payRate = 0.0;
	double grossPay = 0.0;
	double overtime = 0.0;
	double regular = 0.0;
	char another = 'Y';
	do
	{
	cout<<"Enter Number of Hours Worked: ";
	cin>>hours;
	cout<<"Enter Pay Rate: ";
	cin>>payRate;
	cout<<"Calculate for another employee?(Y/N): ";
	cin>>another;
	cout<<endl;
	//call function
	grossPay = getGrossPay(hours, payRate);
	//display gross pay
	cout<<fixed<<setprecision(2)<<endl;
	cout<<"Gross Pay: $"<<grossPay<<endl;
	}while(toupper(another) == 'Y');

	system ("pause");
	return 0;
}//end of main function

//*****function definitions
double getGrossPay(double hours, double payRate, double grossPay, gross )
{
	if (hours>40)
	{
		overtime = (40 - hours) * (1.5 * payRate);
		regular = 40 * payRate;
		grossPay = regular + overtime;
	}
	else	
		grossPay = hours*payRate;
	return grossPay;
}
Does "Total gross pay" mean how much all the employees combined earn?

And line 44 is wrong. What happens if you work 50 hours?
Yes, its the total amount earned by all employees combined.
A function for that is overkill, it's as simple as doing totalGrossPay += GROSS_PAY_FOR_CURRENT_EMPLOYEE inside the cycle, but if that's what the teacher wants you can just put the calculation in a function.

On line 29 you already have the function call to get the current employee's pay but the prototype says it wants two more parameters. You don't need to pass those, as they are calculated inside the function, so fix the prototype and the implementation signature. The implementation itself is also a bit wrong.

getTotalGrossPay() on the contrary needs one more parameter. You can't add to the total if you don't know how much to add.
Topic archived. No new replies allowed.