I have a void function that takes data from an ifstream, reads the first value, (which is an ID #), and compares that value against the ID# info from an array of records. If it's invalid, the rest of the line is ignored. If it's valid, it adds the hours worked to the hours worked field in an array of records. Here is what the input file looks like:
123 7.5
56 6.25
99 an invalid id
555 2.5
123 10.0
My issue is there is the possibility of multiple entries for the same ID# and for the life of me I cannot figure out how/where to place that in my while loop.
Can anyone steer me in the right direction? Code for the function is below.
void get_timedata (ifstream& in, emp_data emp[], int n)
{
int idnum;
int x;
double hours_worked;
in >> idnum;
while (in)
{
x = find(emp, n, idnum);
if (idnum!=emp[x].idnum)
in.ignore(100,'\n');
if (idnum==emp[x].idnum)
{
in>>hours_worked;
emp[x].hours_worked = hours_worked;
}
in >> idnum;
}
}
Thanks in advance.