first of all, segfault always appear when you access a byte or block of memory you dont own.
look at your code
1 2 3 4 5 6 7 8 9 10 11 12
|
for (int i = 0; i < numInfo; i++)
{
if (NUM_HOUR > 0)
cout << left << setw(10) << employee[i].pData.fName << setw(12) << employee[i].pData.lName << setw(10) << employee[i].hoursWorked * employee[i].hourlyRate << endl;
cout << " " << endl;
if (NUM_SALARY > 0)
{
cout << left << setw(10)<< emp[i].pData.fName << setw(12) << emp[i].pData.lName << setw(10) << emp[i].salary + emp[i].bonus << endl;
}
}
|
you overdo a single loop to display employee and emp which their index's sum is equivalent to numInfo. does that makes sense?
lets say i entered 10 as the number of workers,
for (int i = 0; i < numInfo; i++)
this loop will be the same as
for (int i = 0; i < 10; i++)
next if i entered 5 for hourly workers
and 5 for salary workers the value of
will be 5 and
NUM_SALARY
will be 5
and employee array size will be 5 and same with emp array
since you didnt have any break statement in loop or condition that if
i
become 4 the array will not be accessible anymore, the for loop will be force to finish until the i becomes 9 and access the array every iteration of the loop