# Need help writing my code to create an average calculator with C

I am currently a beginner in C programming. I'm trying to create a calculator where the user enters letter grades and the average letter size AND the average GPA value is output.

This is almost complete, unless I can not figure out why the "Average Lettering:" output is not working properly. It works when A is the average and B is the average. However, if you enter a C, D or F average, "Middle letter size is: B" is output.

I hope someone can help, thanks.
PS Sorry if that should not be here. I am also new here.

``````#include
#include

int main (void)
{
while (true) {

unsigned int aCount = 0;
unsigned int bCount = 0;
unsigned int cCount = 0;
unsigned int dCount = 0;
unsigned int fCount = 0;

sets ("Enter the notes");
sets ("Enter EOF to finish the entry.");
int grade;

while ((grade = getchar ())! = EOF) {

change (grade) {

Case & # 39; A & # 39 ;:
Case & # 39; a & # 39 ;:
++ aCount;
break;

Case # B #:
Case # 39:
++ bCount;
break;

Case # C #:
Case # c #:
++ cCount;
break;

Case # D: #
Case # 39:
++ dCount;
break;

Case & # 39; F & # 39 ;:
Case # 39:
++ fCount;
break;

Case & # 39 ;:
Case # 39:
Case & # 39; & # ;: 39
break;

Default:
printf ("% s", "Wrong letter entered.  n");
sets ("Enter a new note.");
break;
}
}

Puts (" nTotals for each note are:");
printf ("A:% u  n", aCount);
printf ("B:% u  n", bCount);
printf ("C:% u  n", cCount);
printf ("D:% u  n", dCount);
printf ("F:% u  n", fCount);

int gradeCount = aCount + bCount + cCount + dCount + fCount;

Float aGPA = aCount * 4.0;
Float bGPA = bCount * 3.0;
Float cGPA = cCount * 2.0;
Float dGPA = dCount * 1,0;
Float fGPA = fCount * 0,0;

Float totalGPA = aGPA + bGPA + cGPA + dGPA + fGPA;

Float avgGPA = totalGPA / gradeCount;

printf ("Average GPA is:% f  n", avgGPA);

if (avgGPA> = 3.5) {
printf ("Average letter note is A  n  n");
}
otherwise if (3.0 <= avgGPA <3.5) {
printf ("Average letternote is B  n  n");
}
otherwise if (2.0 <= avgGPA <3.0) {
printf ("Average letter note is C  n  n");
}
otherwise if (1.0 <= avgGPA <2.0) {
printf ("Average letternote is: D  n  n");
}
miscellaneous
printf ("Average letternote is: F  n  n");
}

}

}
``````

Posted on Categories Articles