Ok i need to read in 2 files. The first file contains employee data, and second file contains employee ID# and the hours the employee worked. I need to matchup the ID numbers and add the hours, which i have done.
my problem is if there is a invalid ID#, i need to ignore the rest of the line, and count the bad IDs. I am having trouble on where and how to place the code, any help would be appreciated.
im sure the code goes in one of these 2 functions. im thinking code should be something like:
if(list.ID != id)
infile.ignore(100, '\n')
counter++;
int find(employee list[],int n,int id)//search for id#
{
for (int i=0; i<n; i++)
if (list[i].ID == id)
return i;
}
void take_inventory(employee list[],int n)
{
ifstream infile;
string filename;
int id;
int place;
double hours, totalHours;
cout << "Enter Work Data Filename " <<endl;
cin >> filename;
infile.open(filename.c_str());
infile >> id;
while (!infile.eof())
{
infile >> hours;
place = find(list,n,id); //locate item by id#
list[place].totalHours=list[place].totalHours+hours;
infile >> id;
}
infile.close();
}