Hello there everyone. I am having a bit of trouble with my C programming. I do not know anything about C programming and this is my first semester and already my professor is putting pressure on me. Anyone that can help would be appreciated.

So I am supposed to create a program that reads from a file with the numbers:

98 96 14 95 88 64 37 72 78 120 86 73 84 73 104 66 92 19 63 45

After that I am supposed to calculate all the grades for each one like A, A+, A-, B, B+, B- C, C+, C-, D, D+, D-, F, all invalid grades less than 21 and more than 100 are considered invalid

So at the end of my code it should print out:

The number of B grades is: 3

The numerical average for a B grade is : 86

The number of B+ grades is: 2

The number of B- grades is: 1

So I am having trouble on how to read all the A grades and do average, all the B grades and do average, and so on. My professor didn't teach us that yet, so I am very confused. Its easy with scanf, but from the file, I don't know. If anyone could help would be so glad. Thanks in advance.

```
#include <stdio.h>
#include <stdlib.h>
int main()
{
int countA = 0;
int gradeA = 0;
int gradeAplus = 0;
int gradeAminus = 0;
int countB = 0;
int gradeB = 0;
int gradeBplus = 0;
int gradeBminus = 0;
int countC = 0;
int gradeC = 0;
int gradeCplus = 0;
int gradeCminus = 0;
int countD = 0;
int gradeD = 0;
int gradeDplus = 0;
int gradeDminus = 0;
int countF = 0;
int invalidcount = 0;
int numA = 0;
FILE* infile;
infile = fopen("lab2_data.txt", "r");
while(!feof (infile) )
{
fscanf(infile, "%d", &numA);
{
if (numA > 100)
{
printf("The number grade %d is invalid\n", numA);
invalidcount = invalidcount + 1;
}
else if (numA >= 96)
{
printf("The number grade %d is a A\n", numA);
countA = countA + 1;
gradeAplus = gradeAplus + 1;
}
else if (numA >= 91)
{
printf("The number grade %d is a A\n", numA);
countA = countA + 1;
gradeAminus = gradeAminus + 1;
}
else if (numA >= 86)
{
printf("The number grade %d is a B\n", numA);
countB = countB + 1;
gradeBplus = gradeBplus + 1;
}
else if (numA >= 81)
{
printf("The number grade %d is a B\n", numA);
countB = countB + 1;
gradeBminus = gradeBminus + 1;
}
else if (numA >= 76)
{
printf("The number grade %d is a C\n", numA);
countC = countC + 1;
gradeCplus = gradeCplus + 1;
}
else if (numA >= 71)
{
printf("The number grade %d is a C\n", numA);
countC = countC + 1;
gradeCminus = gradeCminus + 1;
}
else if (numA >= 66)
{
printf("The number grade %d is a D\n", numA);
countD = countD + 1;
gradeDplus = gradeDplus + 1;
}
else if (numA >= 61)
{
printf("The number grade %d is a D\n", numA);
countD = countD + 1;
gradeDminus = gradeDminus + 1;
}
else if (numA >= 21)
{
printf("The number grade %d is a F\n", numA);
countF = countF + 1;
}
else if (numA < 21)
{
printf("The number grade %d is invalid\n", numA);
invalidcount = invalidcount + 1;
}
}
}
printf("\nThe number of A grades is: %d\n", countA);
printf("The number of A+ grades is: %d\n", gradeAplus);
printf("The number of A- grades is: %d\n", gradeAminus);
printf("\nThe number of B grades is: %d\n", countB);
printf("The number of B+ grades is: %d\n", gradeBplus);
printf("The number of B- grades is: %d\n", gradeBminus);
printf("\nThe number of C grades is: %d\n", countC);
printf("The number of C+ grades is: %d\n", gradeCplus);
printf("The number of C- grades is: %d\n", gradeCminus);
printf("\nThe number of D grades is: %d\n", countD);
printf("The number of D+ grades is: %d\n", gradeDplus);
printf("The number of D- grades is: %d\n", gradeDminus);
printf("\nThe number of F grades is: %d\n", countF);
printf("\nThe number of invalid grades is: %d\n", invalidcount);
fclose(infile);
return(0);
}
```

*Edited 5 Years Ago by cufisa*: I accidentally removed the bracket after code