Skip to the task
Layout
Back to classic view

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

RUNTask 5 of 22 · step 3: A grade in wordsRun it and type 8
Run it and type 8 in practice/03/

File → Reload CMake Project, pick p03_grades and ▶. Type 8.

Checklist

  • Every task is one commit with a clear message.

Numbered notes in the code explain the important lines.

Details & hint
$ .\build\debug\practice\03\p03_grades.exe
Grade: 8
Good

You should see: The grade as a word. Try the edges too: 1, 4, 5, 10.

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;
+ }
opened for this task
$ .\build\debug\practice\03\p03_grades.exe
Grade: 8
Good