The Ada Program: days.adb
1 -- days.adb: example use of the case statement
2
3 with Ada.Text_IO, Ada.Integer_Text_IO;
4 use Ada;
5
6 procedure Days is
7
8 type Month_Type is (Jan, Feb, Mar, Apr, May, Jun,
9 Jul, Aug, Sep, Oct, Nov, Dec);
10
11 package Month_IO is new Text_IO.Enumeration_IO (Enum=>Month_Type);
12 Month : Month_Type;
13 Days_In_Month : Integer range 1 .. 31;
14 Leap_Year : constant Boolean := FALSE;
15
16 begin
17
18 Input: loop
19
20 Text_IO.Put ("Enter a month (Jan to Dec) -- ");
21 Text_IO.Flush;
22
23 exit when Text_IO.End_Of_File;
24 Month_IO.Get (Month);
25 Text_IO.Skip_Line;
26
27 case Month is
28 when Sep | Apr | Jun | Nov =>
29 Days_In_Month := 30;
30 when Feb =>
31 if Leap_Year then
32 Days_In_Month := 29;
33 else
34 Days_In_Month := 28;
35 end if;
36 when others =>
37 Days_In_Month := 31;
38 end case;
39
40 Text_IO.Put ("There are ");
41 Integer_Text_IO.Put (Days_In_Month, Width=>0);
42 Text_IO.Put (" days in the month of");
43 Month_IO.Put (Month);
44 Text_IO.Put_Line (".");
45 end loop Input;
46
47 end Days;