function running twice

Hello, I am new to C++ and just started learning functions. My problem is that when I run the program it asks me to enter the number of employees twice. Here is the code.

#include <iostream>
using namespace std;

int getEmployee();
int getDays();
//double getAverage(int, int);

int main()
{
int employee, totalMissed;
//double average;

employee=getEmployee();
totalMissed=getDays();
//average=getAverage();

cout<<"There are "<<employee<<" employees.\n";
cout<<"They missed a total of "<<totalMissed<<" days.\n";
//cout<<"The average number of days missed is "<<average<<".\n";
system("pause");
return 0;
}

int getEmployee()
{
int employee;
cout<<"Enter the number of employees.\n";
cin>>employee;

while (employee<1)
{
cout<<"There must be 1 or more employees.\n";
cin>>employee;
}

return employee;
}

int getDays()
{
int days, employee, count, totalMissed;
employee=getEmployee();
totalMissed=0;

for(count=1; count<=employee; count++)
{
cout<<"How many days did employee number "<<count<<" miss.\n";
cin>>days;

while(days<0)
{
cout<<"Employees can not miss less than zero days.\n";
cin>>days;
}

totalMissed+=days;
}

return totalMissed;
}
//double getAverage()
//{

//}

Ignore the commented part. The program is not done. I just need to get the double question fixed before I move on. I have been staring at the screen and flipping through my book for a while now. Any help would be greatly appreciated.
You call getEmployee() function twice - in main() and in getDays(). To avoid this, you can pass int employee as a parameter to getDays function
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
int getDays(int employee);

int main()
{
// ...
  totalMissed=getDays(employee);
// ...
}

int getDays(int employee)
{
// remove   employee=getEmployee();
// ...
}
Thanks, that fixed it. And you stopped me from making an error on the next part. My professor barely mentioned parameters during her lecture.
Topic archived. No new replies allowed.