I have a program where I am trying to sum grades that are input by the end user. They can put in a max of 10 grades. The grades must be between 1-100. If they put in a number above or below they get an error message. When I run the program my "sum" command is adding in the grades that are in error. I was hoping someone could give me help?????

Code:

#include <stdio.h>
int minimum (int grades[], int no_of_grades);
int maximum (int grades[], int no_of_grades);
int main()
{
int grades[10], i, min_grades = 0;
int max_grades = 0;
int sum = 0;
int no_of_grades = 0;
int avg = 0;
do
{
printf ("Enter the number of grades to process (0-10): ", no_of_grades);
scanf ("%i", &no_of_grades);
fflush (stdin);
if (no_of_grades < 1 || no_of_grades > 10)
printf ("Invalid number of grades.\n");
} while (no_of_grades < 1 || no_of_grades > 10);
for (i = 0; i < no_of_grades; i++ )
do
{
printf ("Enter grade for student #%i: ",i+1);
scanf ("%i", &grades[i]);
fflush(stdin);
if (grades[i] <= 0 || grades[i] >= 101)
printf ("***Invalid grade entered. Please enter 0 - 100.***");
sum = sum + grades[i];
} while (grades[i] <= 0 || grades[i] >= 101);
printf ("\nThe sum of all grades is %i",sum);
avg = sum / no_of_grades;
min_grades = minimum(grades, no_of_grades);
max_grades = maximum(grades, no_of_grades);
printf ("\nThe class average is %i",avg);
printf ("\nThe minimum grade is %i",min_grades);
printf ("\nThe maximum grade is %i",max_grades);
getchar();
} /*End Main*/
int minimum (int grades[], int no_of_grades)
{
int min_grades, i;
min_grades = grades[0];
for (i = 1; i < no_of_grades; ++i)
if (grades[i] < min_grades)
min_grades = grades[i];
return min_grades;
}
int maximum (int grades[], int no_of_grades)
{
int max_grades, i;
max_grades = grades[0];
for (i = 1; i < no_of_grades; ++i)
if (grades[i] > max_grades)
max_grades = grades[i];
return max_grades;
}