Skip to the task
Layout
Back to classic view

You are looking ahead. Your place is still task 1: Conditions.

CREATETask 4 of 22 · step 3: A grade in wordsA grade in words
A grade in words in practice/03/

Read a grade, check it with if and write it in words with switch.

Checklist

  • Every task is one commit with a clear message.

Numbered notes in the code explain the important lines.

Details & hint
  • A grade outside 1–10 is an error: say so and end with return 1;.
  • Grades 10 to 5 each get their own case with break.
  • default gets everything else: after the check only 1–4 are left, and those are "Unsatisfactory".

Stuck? Anything but 0 from main means "ended unsuccessfully". CLion shows it as Process finished with exit code 1.

practice 03 main.c Code Diff +36
A · NEW FILE git diff: every line is new (+36).
--- /dev/null
+++ b/practice/03/main.c
@@ -0,0 +1,36 @@
+ #include <stdio.h>
+
+ #include "input.h"
+
+ int main(void) {
+ int grade = read_int("Grade: ");
+ if (grade < 1 || grade > 10) {
+ printf("Grade must be between 1 and 10.\n");
+ return 1;
+ }
+
+ switch (grade) {
+ case 10:
+ printf("Excellent\n");
+ break;
+ 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:
+ printf("Unsatisfactory\n");
+ break;
+ }
+ return 0;
+ }