Code
A grade in words
Create practice/03 with CMakeLists.txt and main.c. This time input.h is needed from the start, so CMakeLists.txt has two lines already:
add_executable(p03_grades main.c)
target_link_libraries(p03_grades PRIVATE course_input)
main.c reads one grade and writes it in words.
- A check with
if. A grade outside 1–10 is an error: the program says so and ends withreturn 1;. Non-zero means "ended unsuccessfully". - The word with
switch. Grades 10 to 5 get acaseeach, anddefaulttakes the rest: after the check only 1–4 are left, and those are "Unsatisfactory".
Run it
Type 8:
Grade: 8
Good
Now run it again and type 11:
Grade: 11
Grade must be between 1 and 10.
Process finished with exit code 1
exit code 1 is your return 1;. Try the limits too: 1, 4, 5, 10.
Commit: Print grade in words.