The Ada Program: grade.adb
1 -- grade.adb: example use of the case statement
2
3 with Ada.Text_IO, Ada.Integer_Text_IO;
4 use Ada;
5
6 procedure Grade is
7
8 Score : Integer range 0 .. 100;
9 Letter: Character;
10
11 begin
12
13 Input: loop
14
15 Text_IO.Put ("Enter a test score (0 to 100) -- ");
16
17 -- We must test for EOF after prompt, because it
18 -- blocks waiting for input.
19 exit when Text_IO.End_Of_File;
20
21 Integer_Text_IO.Get (Score);
22 Text_IO.Skip_Line; -- discard rest of the line
23
24 case Score is
25 when 91 .. 100 => Letter := 'A';
26 when 81 .. 90 => Letter := 'B';
27 when 71 .. 80 => Letter := 'C';
28 when 61 .. 70 => Letter := 'D';
29 when others => Letter := 'F';
30 end case;
31
32 Text_IO.Put ("A score of '");
33 Integer_Text_IO.Put (Score, Width=>0);
34 Text_IO.Put_Line ("' is the letter grade '" & Letter & "'.");
35
36 end loop Input;
37
38 end Grade;