My code is supposed to accept user input to make an array for grades. Then compute the average and sum of the array. Also, it is supposed to display an asterisk beside the grade if it below average, and the letter grade.
Any suggestions of how to clean up the code or clean up any of the errors I am getting like numel and grade being undeclared identifier in my first for loop. I am looking to learn so any critique and help will be great appreciated
Code:
double findSum(double[], int);
double findAvg(double [], int);
int main()
{
#define NUMELS 100
#define CUTOFF -1
static double grades[100];
double average, sum;
int i;
printf("Enter the grades, when finished enter a negative number: ");
while (grades < CUTOFF.o
{
printf("Enter a grade: ");
scanf("%f", &grades[100]);
}
average = findAvg(grades, NUMELS);
sum = findSum(grades, NUMELS);
printf("The sum of the grades is %f", sum);
printf("The average of the grades is %f", average);
for (i = 0; i < numel; i++)
if (grade[i] < average)
printf("*%f", i)
else if
printf("%f", i);
if (grade[i] >= 90)
printf("%f A", i);
else if (grade[i] >= 80 && grade [i] < 90)
printf("%f B", i);
else if (grade[i] >= 70 && grade [i] < 80)
printf("%f C", i);
else if (grade[i] >= 60 && grade [i] < 70)
printf("%f D", i);
else
printf("%f F", i);
return 0;
}
double findAvg(double grades[], int numel)
{
int i;
double sumnums = 0.0;
for (i = 0; i < numel; i++)
sumnums = sumnums + grades[i];
return (sumnums/numel); /*calculate and return average*/
}
double findSum(double grades[], int numel)
{
int i;
double sumnums = 0.0;
for (i = 0; i < numel; i++)
sumnums = sumnums + grades[i];
return (sumnums); /*reutrn the sum*/
}