The Ada Program: temperature.adb

  1 -- temperature.adb:  high and low temperatures over 24 hours
  2 
  3 with Ada.Text_IO, Ada.Integer_Text_IO; use Ada;
  4 
  5 procedure Temperature is
  6 
  7    Num_Hours : constant Integer := 24; -- Number of hours in time period
  8 
  9    Temp : Integer;                     -- An hourly temperature reading
 10    High : Integer := Integer'First;    -- Highest temperature so far
 11    Low  : Integer := Integer'Last;     -- Lowest temperature so far
 12 
 13 begin
 14 
 15    -- Prompt user for all input once
 16    Text_IO.Put (Item => "Enter 24 temperatures");
 17    Text_IO.New_Line;
 18 
 19    for Hour in 1..Num_Hours loop
 20 
 21       -- Get and echo an hourly temperature
 22       Integer_Text_IO.Get (Item => Temp);
 23       Integer_Text_IO.Put (Item => Temp, Width => 4);
 24 
 25       -- Lowest temperature so far?
 26       if Temp < Low then
 27          Low := Temp;
 28       end if;
 29 
 30       -- Highest temperature so far?
 31       if Temp > High then
 32          High := Temp;
 33       end if;
 34 
 35    end loop;
 36 
 37    -- Print high and low temperatures
 38    Text_IO.New_Line;
 39    Text_IO.Put (Item => "High temperature is ");
 40    Integer_Text_IO.Put (Item => High, Width => 0);
 41    Text_IO.New_Line;
 42    Text_IO.Put (Item => "Low temperature is ");
 43    Integer_Text_IO.Put (Item => Low, Width => 0);
 44    Text_IO.New_Line;
 45 
 46 end Temperature;