I am writing a program to calculate the average of an array of 10 floating-point values. I am trying to write it so that the value entered by the user goes straight to the array.
My problem is that the program isn't adding up the values in the array.
Code:
// Program to calculate the average of an array of 10 floating-point values
#include <stdio.h>
int main (void)
{
float grades[10], average;
int i, gradeTotal = 0;
for ( i = 1; i <= 10; ++i ) {
printf ("Enter 10 values to be averaged #%i: ", i);
scanf ("%i", &grades[i]);
gradeTotal = gradeTotal + grades[i];
}
average = (float) gradeTotal / 10;
printf ("\nGrade average = %.2f\n", average);
return 0;
}