Originally Posted by
seasali
Your compilator cannot communicate correctly with conio.
I've got to write that down somewhere once I stop laughing long enough.
Originally Posted by
seasali
Instead "#include <conio>" use "#include <conio.h>
Nobody in this thread has used #include <conio> to my knowledge.
Ok, back to business:
Code:
void average_scores(double scores[], int length)
{ double sum, average;
scores[0] = 0;
scores[length] = 0;
sum = 0;
for(int m = 0; m < length; ++m)
sum = sum + scores[m];
average = sum / (length - 1);
cout << endl << "The average score given is: " <<
setiosflags(ios::showpoint|ios::fixed) << setprecision(2) << average << endl;
getch();
}
What on earth do you expect that to do? Why do you clobber the first score, and then write to scores[length], which is out of bounds as people told you earlier?
First, arrays in C (and C++) start at index 0. Hence scores[0] is the first item. If you declare an array as double scores[10], it has ten doubles: the first is scores[0], the last scores[9].
Now, to rewrite your function:
Code:
void average_scores(double scores[], int length)
{
double sum = 0, average;
for(int m = 0; m < length; ++m) sum += scores[m];
average = sum / length;
cout << endl << "The average score given is: " <<
setiosflags(ios::showpoint|ios::fixed) << setprecision(2) << average << endl;
getch();
}