I don't understand this intention of this code:
206 207 208 209 210 211 212 213 214
|
// display employess with below average gross pay
void displaylowGrossID(double lowAverageID[], double grossPay[])
{
std::cout << "\nEmployees With Below Average Gross Pay:\n";
for (int x = 0; x < lowAverageID[x]; x++)
{
cout << lowAverageID[x] << " -- $" << grossPay[x] << endl;
}
}
|
At line 210, the integer x is compared with the floating-point value in array location
lowAverageID[x]
. This location may contain a valid employee id, or else it could contain uninitialised data (effectively a random value in the range -inf to +inf, or nan).
The loop may exit prematurely, before all the values were output, or else it may fail to exit before outputting spurious values.
The design of the mechanism here I think needs to be reconsidered. One possibility is to set the value to zero if it is not used, and then loop through all five values, but print the result only if it is non-zero.
There are other solutions, including the use of a vector which would start out empty, and contain only the required data.