Hello, I was wondering if anyone had any ideas for how to fix the errors that I am getting.
The code compiles correctly, but there are a few error messages when I run it in Visual Studio.
It says that the variables 'largest' and 'smallest' are being used without initializing. If you ignore the error message, it runs fine.
The other problem I am having is that in the "highest" function, I am getting a strange number....the debugger is giving me the correct numbers for average and lowest, but the highest is coming back as -8.58993e.
The uninitialized variables are a serious error - it means those variables contain garbage and will very likely give incorrect results. The "strange" number you get is a direct consequence of that.
There are a couple of other issues too. The array subscript count must be an integer, not a floating-point type. The first element of the array is ignored in functions highest() and lowest(). The < and > signs are used the wrong way round (lines 74 and 85).
You can fix both the uninitialised variable and the ignoring of the first element by setting the initial value equal to the first array element.
1 2 3 4 5 6 7 8 9 10 11
double highest (double* score, int numScores)
{
double largest = score[0];
int count;for (count = 1; count < numScores; count++)
{
if (score[count] > largest)
largest = score[count];
}
return largest;
}