A loop over the grades
One grade isn't much. Let the program ask how many grades there will be and write each one in words.
A loop around what you have
At the start: int count = read_int("How many grades? "); and int sum = 0;. Then all of the grade reading and the switch move inside a for:
for (int i = 1; i <= count; i++) {
printf("%d. ", i);
int grade = read_int("Grade: ");
...
sum += grade;
}
printf("%d. ", i) writes the number before the question, so you see 2. Grade:.
if becomes while
Before, an invalid grade ended the program with return 1;. In a loop that is bad: one mistake would throw away all the grades typed so far. So the if becomes a while: as long as the grade doesn't fit, say what's wrong and ask again.
while (grade < 1 || grade > 10) {
printf("Grade must be between 1 and 10.\n");
grade = read_int("Grade: ");
}
The average
After the loop: (double)sum / count. Without (double) it would be integer division (topic 2).
Run it
Type 3, then 9, 11, 4, 10:
How many grades? 3
1. Grade: 9
Very good
2. Grade: 11
Grade must be between 1 and 10.
Grade: 4
Unsatisfactory
3. Grade: 10
Excellent
Average: 7.67
Now run it and answer 0 to "How many grades?":
How many grades? 0
Average: nan
The loop didn't run even once, and 0 / 0 is not a number: nan. You fix that in the next step.
Commit: Loop over grades.