Skip to the task
Layout
Back to classic view

You are looking at lesson 3. Your place is still lesson 10, task 1: struct.

CHECKTask 6 of 22 · step 3: A grade in wordsRun it with 11
Run it with 11 in practice/03/

Run it again and type 11. What does the program print, and with which code does it end?

Numbered notes in the code explain the important lines.

Details & hint

Stuck? "Grade must be between 1 and 10." and Process finished with exit code 1: that is your return 1;. The switch is never reached.

practice 03 main.c Code Diff +36
A · NEW FILE Create this file. Every line is new: see the green bar.
#include <stdio.h>
#include "input.h"
int main(void) {
int grade = read_int("Grade: ");
if (grade < 1 || grade > 10) {
Note 1: ||: it is enough for one side to be true.
printf("Grade must be between 1 and 10.\n");
return 1;
Note 2: Not 0: the program ended unsuccessfully.
}
switch (grade) {
Note 3: switch compares grade with each case.
case 10:
printf("Excellent\n");
break;
Note 4: break leaves the switch; without it the next case runs too.
case 9:
printf("Very good\n");
break;
case 8:
printf("Good\n");
break;
case 7:
printf("Fair\n");
break;
case 6:
printf("Satisfactory\n");
break;
case 5:
printf("Weak\n");
break;
default:
Note 5: Everything else: here only 1–4.
printf("Unsatisfactory\n");
break;
}
return 0;
}