issues with my pass by reference lab

Hey!
So my program below is used to find the highest and lowest gross of employees, print out both the high and low gross, those 2 employees names and then find the average gross of all employees entered. The issue is that the program can get the highest gross but no matter how I code this the lowest gross is always empty. Any idea what is happening?

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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112

#include <iostream>
#include <string>
#include <cmath>
#include <iomanip>

using namespace std;
void highLowStart(double grossPay, string userName, double&highestGross, double&lowestGross, string&lowGrossUser, string&highGrossUser)
{
	highestGross = grossPay;
	lowestGross = highestGross;
	lowGrossUser = userName;
	highGrossUser = lowGrossUser;
}

void highestGrossMethod(double grossPay, string userName, double&totalGrossPay, string&highGrossUser, double&highestGross)
{
	totalGrossPay = totalGrossPay + grossPay;
	if (grossPay > highestGross)
	{
		highestGross = grossPay;
		highGrossUser = userName;
	}
}

void lowestGrossMethod(double grossPay, string userName, double&totalGrossPay, string&lowGrossUser, double&lowestGross)
{
	if (grossPay < lowestGross)
	{
		lowestGross = grossPay;
		lowGrossUser = userName;
	}
}
int main()
{
	int count = 0;
	string userName;
	int hoursWorked;
	double hourlyWage;
	double grossPay;
	double highestGross = 0;
	double lowestGross =0;
	string highGrossUser = " ";
	string lowGrossUser = " ";
	double totalGrossPay = 0;
	double averageGrossPay;
	double stateTax;
	double fedTax;
	char redoLoop = 'y';
	int count1 = 0;
	do
	{
		count1++;
		cout << endl << "Hello user, please enter your name: ";
		cin >> userName;
		cout << endl << "Please enter the total number of hours worked: ";
		cin >> hoursWorked;
		if ((hoursWorked > 60) || (hoursWorked < 0))
		{
			cout << endl << "that number is invalid, please enter a new one: ";
			cin >> hoursWorked;
		}
		cout << endl << "Please enter your hourly wage: ";
		cin >> hourlyWage;
		if ((hourlyWage < 0) || (hourlyWage > 42.47))
		{
			cout << endl << "that number is invalid, please enter a new one: ";
			cin >> hourlyWage;
		}
		grossPay = (hourlyWage*hoursWorked);
		cout << endl << "Please enter state tax: ";
		cin >> stateTax;
		if ((stateTax < 0) || (stateTax > 10))
		{
			cout << endl << "that number is invalid, please enter a new one: ";
			cin >> stateTax;
		}
		stateTax = (stateTax * .01)*grossPay;
		cout << endl << "Please enter federal tax rate: ";
		cin >> fedTax;
		if ((fedTax < 0) || (fedTax > 25))
		{
			cout << endl << "that number is invalid, please enter a new one: ";
			cin >> fedTax;
		}
		fedTax = (fedTax*.01)* grossPay;
		grossPay = grossPay - fedTax - stateTax;
		if (count == 1)
		{
			highLowStart(grossPay, userName, highestGross, lowestGross, lowGrossUser, highGrossUser);
		}
		if (grossPay > highestGross)
		{
			highestGrossMethod(grossPay, userName, totalGrossPay, highGrossUser, highestGross);
		}
		if (grossPay < lowestGross)
		{
			lowestGrossMethod(grossPay, userName, totalGrossPay, lowGrossUser, lowestGross);
		}
		cout << endl << "Would you like to enter another employee? Please enter either a y for yes or an n for no: ";
		cin >> redoLoop;
	}
	 while (redoLoop != 'n');
	averageGrossPay = totalGrossPay / count;
	cout << "The higest gross pay was " << highestGross << " and that was owned by " << highGrossUser << endl;
	cout  << "The lowest gross pay was " << lowestGross << " and that was owned by " << lowGrossUser << endl;
	cout  << "The average gross was " << averageGrossPay << endl;
	system("pause");
	return 0;
}

The problem is on line 90: On line 11 you try to set lowestGross = highestGross;, but highestGross isn't calculated at that point and therefore 0.

By the way: You increase count1 but never count, hence count will never become anything else but 0
Topic archived. No new replies allowed.