void and value returning function problem

would anyone be kind enough to help fix my code for this void function this is due very soon and ive been working hard and posted a few times on here and i still cant seem to get it right and i have working on for about a week and im having alot of trouble with void functions here is the question
"The payroll manager at Gerston Blankets wants a program that calculates and displays the gross pay for
each of the company’s employees. It also should calculate and display the total gross pay. 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 void function
to determine an employee’s gross pay. Use a value-returning func-tion 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."

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;

void getGrossPay(int hours, double rate,double& pay);

int main()
{
	// declare variables  
	int hrsWrk = 0;
	double payRate = 0.0;
	double totalGrossPay = 0.0;
	char   sentinel = ' ';

	getGrossPay(hrsWrk, payRate, totalGrossPay);

	// 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);
		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;
}
What actually is the problem - compile errors, wrong output, no output, crash....?
Compile errors
Observe that lines 7 and 46 are different.
Can you please explain why you thought that this would make any sense?

Compile errors

Compile errors are there to help you find the problem, not just indicate whether your code works or not. I suggest you start reading them.
Last edited on
Prototype:
void getGrossPay(int hours, double rate, double& pay);

Definition:
double getGrossPay(double hrsWrk, double payRate)

Spot the difference(s)?



"Use a void function to determine an employee’s gross pay" - that's one function.
"Use a value-returning function to accumulate the total gross pay - that's a second function.

R.T.Q.
Last edited on
Topic archived. No new replies allowed.