void get_workdata(ifstream& in, emp_rec anc_emp[], int n)
{
int x;
double y;
int cnt = 0;
for (int i=0; i<n; i++)
{
anc_emp[i].hoursworked = 0.0;
anc_emp[i].commission = 0.0;
}
in >> x;
while (x >= 0)
{
in >> y;
for (int i=0; i<n; i++)
{
if (x = anc_emp[i].idnum)
{
anc_emp[i].hoursworked = anc_emp[i].hoursworked + y;
cnt = cnt;
}
if (x != anc_emp[i].idnum)
{cnt++;
}
}
if (cnt = n)
{
cout << "Error: unassignmed ID# " << x << " with " << y << " hours."
<< endl;
}
in >> x;
}
}
So basically the first data set is this:
(employee name, idnumber, payrate)
tom 46 7.50
saLLy 53 8.25
VanEssA 91 5.85
The second data set is this:
(idnumber, hours worked)
91 10.0
11 15.0
46 8.0
91 4.5
53 20.0
91 6.75
56 40.0
-3
I am supposed to create employee records and sum the hours worked and figure the total pay. So far, I have everything down EXCEPT for my function that reads in the idnumber, then the hours worked for that idnumber. If the id matches an id from file1, the hours need to be added. If the id number doesn't match, an error message will print that states it's an invailid id number. I denoted 'x' as the idnumber being read in and 'y' as the hours worked for that id number.
Here is my algorithm:
1. Read in the first id number
2. While id number is not negative,
3. Read in hours worked.
4. Set up a For loop
a) If x equals an idnumber from file 1, then add the hours worked to that
record.
b) Else: add one to 'cnt'
After for loop runs through all the id numbers from file 1,
5. If cnt = n (the number of employee records) then the current x value doesn't match any of the id numbers from file1 and is an invalid id number and a message will print.
6. Read in x (next id number)
My program compiles, but when I run it, I get this:
Error: unassigned ID# 91 with 10 hours.
Error: unassigned ID# 91 with 15 hours.
Error: unassigned ID# 91 with 8 hours.
Error: unassigned ID# 91 with 4.5 hours.
Error: unassigned ID# 91 with 20 hours.
Error: unassigned ID# 91 with 6.75 hours.
Error: unassigned ID# 91 with 40 hours.
Could anyone please look at my function get_workdata and see if you can find any errors because I am stuck!