File input using >> problems
Nov 21, 2010 at 8:44pm UTC
If someone could explain to me why this code doesn't work, that would be great.
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
#include <iostream>
#include <iomanip>
#include <fstream>
using namespace std;
void display_days (int []);
void total_days (int []);
void average_days (int []);
void maximum_days (int []);
void minimum_days (int []);
int main()
{
char employeesfile[51];
int total_employees;
int employees[50] ;
ifstream inFile;
cout << "\tCALCULATE AVERAGE EMPLOYEE ABSENCE\n" ;
cout << "Please enter the name of the input file: " ;
cin >> employeesfile;
inFile.open(employeesfile);
inFile >> total_employees;
if (total_employees <= 0)
cout << "\nInvalid number of employees." ;
for (int count = 0; count < employees[0]; count++)
inFile >> employees[count];
return 0;
}
Nov 21, 2010 at 9:43pm UTC
for (int count = 0; count < employees[0]; count++)
why would you compare to employees[0] ? it's not even initialised..
total_employees is the number of ints to read, so compare to it.
Topic archived. No new replies allowed.