The Ada Program: obese.adb
1 with Ada.Text_IO, Ada.Integer_Text_IO, Ada.Float_Text_IO;
2 use Ada;
3
4 procedure Obese is
5
6 type Gender_Type is (Male, Female);
7 package Gender_IO is new Text_IO.Enumeration_IO (Gender_Type);
8 Message : constant String := "Enter gender (male/female), " &
9 "height (in inches), and weight (in pounds)";
10 Gender : Gender_Type;
11 Height_Inches, Weight_Pounds : Positive;
12 Height_Meters, Weight_Kilos, Body_Mass_Index: Float;
13 type Cutoff_Type is array (Gender_Type) of Float;
14 Cutoff : Constant Cutoff_Type := (27.8, 27.3);
15
16 begin
17 -- get gender, height, and weight
18 Text_IO.Put_Line (Message);
19 Text_IO.Put ("=> ");
20 Gender_IO.Get (Gender);
21 Integer_Text_IO.Get (Height_Inches);
22 Integer_Text_IO.Get (Weight_Pounds);
23
24 -- compute body mass
25 Height_Meters := Float(Height_Inches)/39.37;
26 Weight_Kilos := Float(Weight_Pounds) / 2.2;
27 Body_Mass_Index := Weight_Kilos / (Height_Meters**2);
28
29 -- print result
30 Text_IO.Put ("Body mass index of ");
31 Float_Text_IO.Put (Body_Mass_Index, Fore=>2, Aft=>2, Exp=>0);
32 Text_IO.Put (" kg/m**2 is ");
33 if (Body_Mass_Index < Cutoff (Gender)) then
34 Text_IO.Put ("not ");
35 end if;
36 Text_IO.Put_Line ("considered obese for ");
37 if Gender=Female then
38 Text_IO.Put ("nonpregnant ");
39 end if;
40 Gender_IO.Put (Gender, Set=>Text_IO.Lower_Case);
41 Text_IO.Put_Line ("s by the Centers of Disease Control.");
42 end Obese;