Why doesn't the loop repeat?

The ID number and the absences is supposed to repeat 5 times (the number of employees), but it's not.


I have this:


#include <iostream>
#include <string>
#include <fstream>
#include <iomanip>
using namespace std;



int getEmployeeNumber();
int fileAndEmployees (ofstream& outFile, int);




int main() {

ofstream outFile;
outFile.open ("employeesAbsent.txt");

cout << fixed << showpoint << setprecision(1);

int employeeNum;
employeeNum = getEmployeeNumber();
fileAndEmployees (outFile, employeeNum);




outFile.close();


return 0;
}


int getEmployeeNumber()

{
int employeeNumber;
cout << "Please enter the number of employees in the company: "<<endl;
cin >> employeeNumber;
return employeeNumber;
}

int fileAndEmployees(ofstream& outFile, int employees)
{
outFile << employees;

for (employees = 1; employees < 5; employees++);
{
int idNumber;
cout << "Please enter an employee ID: "<<endl;
cin >> idNumber;
int daysAbsent;
cout << "Please enter the number of days this employee was absent: "<<endl;
cin>> daysAbsent;
return employees;
}


}


and this is the result:

Please enter the number of employees in the company:
5
Please enter an employee ID:
123
Please enter the number of days this employee was absent:
2
Program ended with exit code: 0

(It only goes once)
Probably because of a "random" semicolon being present at the end of your loop statement.

Why are you passing "employees" into the function? Wouldn't it be better to loop for the number of "employees" instead of a random magic number?

Topic archived. No new replies allowed.