Example program – Letter grade program (Video)
Write a program where user will enter 3 test scores, calculate the average of the 3 test scores and print
the letter grade using the average.
Average Letter grade
90 – 100 A
80 – 89 B
70 – 79 C
0 – 69 F
Otherwise not valid
#include <stdio.h>
int main()
{
//Declaration
int test1, test2, test3, sum;
int avg;
//Data/input
printf("Enter test1 : ");
scanf("%d", &test1);
printf("Enter test2 : ");
scanf("%d", &test2);
printf("Enter test3 : ");
scanf("%d", &test3);
//Calculation
sum = test1 + test2 + test3;
avg = sum / 3;
//if statements and output
if (avg >= 90 && avg <= 100)
printf("A\n");
if (avg >= 80 && avg <= 89)
printf("B\n");
if (avg >= 70 && avg <= 79)
printf("C\n");
if (avg >= 0 && avg <= 69)
printf("F\n");
if (avg < 0)
printf("Not valid, less than 0\n");
if (avg >100)
printf("Not valid, greater 100\n");
return 0;
}
Or
if (avg < 0 || avg > 100)
printf("Not valid\n");