Problem with getting an average from a function

Hey guys, bit of a problem here. We're just getting into functions in my C++ class, and I'm having trouble getting the average to go to main to be output. It always outputs the average as 0, but everything else goes through just fine. I'd really appreciate some tips/advice on what to do and to possibly explain what I'm doing wrong. It's not due till next Tuesday, so there's plenty of time.

I suppose the problems would probably be on lines: 8, 21, 25, and 76-81 if that helps at all.

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

using namespace std;

int employees();
int days(int);
double average(int, int);

int main()
{
	char repeat;
	int totalEmployees;
	int totalDaysMissed;
	double finalAverageMissed;

	do
	{
		totalEmployees = employees();
		totalDaysMissed = days(totalEmployees);
		finalAverageMissed = average(totalEmployees, totalDaysMissed);

		cout << "\nThere are " << totalEmployees << " employees in the company." << endl;
		cout << "In total, they missed " << totalDaysMissed << " days." << endl;
		cout << "The average of the total days missed is: " << finalAverageMissed << endl;

		cout << "\nWould you like to run the program again? (Y/N)" << endl;
		cin >> repeat;
		cout << endl;
	}while(repeat == 'y' || repeat == 'Y');

	return 0;
}


int employees()
{
	int numEmployees;

	cout << "Please enter the number of employees in the company." << endl;
	cin >> numEmployees;

	while(numEmployees < 1)
	{
		cout << "Please enter a number greater than 1 for the number of employees." << endl;
		cin >> numEmployees;
	}

	return numEmployees;
}

int days(int numEmployees)
{
	int daysMissed;
	int totalMissed = 0;

	cout << "\nPlease enter the total days missed for each employee." << endl;

	for (int i = 0; i < numEmployees; i++)
	{
		cout << "Employee #" << (i + 1) << ": ";
		cin >> daysMissed;

		while(days < 0)
		{
			cout << "Please enter a positive number for the days missed." << endl;
			cin >> numEmployees;
		}

		totalMissed += daysMissed;
	}

	return totalMissed;
}

double average(int totalMissed, int numEmployees)
{
	double averageMissed = (totalMissed / numEmployees);

	return averageMissed;
}
At line 78 you're doing integer division, so unless totalMissed is > num_Employees you're going to be assigning 0 to averageMissed. Cast totalMissed and numEmployees to double BEFORE dividing.
Ah, I could see where that would've caused an issue. Didn't pop into my mind to do that though. Also had to switch

double average(double totalMissed, double numEmployees)

in line 76 to

double average(double numEmployees, double totalMissed)

or else it would divide the number of employees by the missed days instead of the way it's supposed to. I don't really see how that would cause a problem though, but as soon as I saw it I figured it out. It's working just fine now, just a little bit confused as to why the arguments have to be in that order.
The arguments have to be in that order, because they are positional and that is the order you specify them in line 21:
 
finalAverageMissed = average(totalEmployees, totalDaysMissed);
Makes sense, won't make that mistake in the future. Thank you for the help!
Topic archived. No new replies allowed.