Example: Day of the Week

Let's write a program that prints the day of the week (in English) depending on the given number (1 … 7) or "Error!" if an invalid input is given.

Sample Input and Output

Input Output
1
7
-1
Monday
Sunday
Error!

Solution

It is a good practice to put at the first place those case statements that process the most common situations, and leave the case constructions processing the more rear situations at the end, before the default construction. Another good practice is to arrange the case labels in ascending order, regardless of whether they are integral or symbolic.

Testing in the Judge System

Test your solution here: https://judge.softuni.bg/Contests/Practice/Index/508#8.

results matching ""

    No results matching ""