home *** CD-ROM | disk | FTP | other *** search
/ Chip 1995 March / CHIP3.mdf / programm / prog4 / summer.ada < prev    next >
Encoding:
Text File  |  1991-07-01  |  1.1 KB  |  48 lines

  1.                                        -- Chapter 19 - Program 1
  2. with Text_IO;
  3. use Text_IO;
  4.  
  5. procedure Summer is
  6.  
  7.    package Int_IO is new Text_IO.Integer_IO(INTEGER);
  8.    use Int_IO;
  9.  
  10.    type MY_ARRAY is array (POSITIVE range <>) of INTEGER;
  11.  
  12.    Dummy1 : constant MY_ARRAY := (27,14,13,33);
  13.    Dummy2 : constant MY_ARRAY := (112 => 27, 113 => 14,
  14.                                   114 => 13, 115 => 33);
  15.  
  16.    My_List : MY_ARRAY(1..12);
  17.    Stuff   : MY_ARRAY(4..8) := (12,13,7,11,125);
  18.    Total   : INTEGER;
  19.  
  20.       function Sum_Up(In_Array : MY_ARRAY) return INTEGER is
  21.       Sum : INTEGER := 0;
  22.       begin
  23.          for Index in In_Array'FIRST..In_Array'LAST loop
  24.             Sum := Sum + In_Array(Index);
  25.          end loop;
  26.          Put("The sum of the numbers is");
  27.          Put(Sum);
  28.          New_Line;
  29.          return Sum;
  30.       end Sum_Up;
  31.  
  32. begin
  33.    My_List := (0,1,2,3,4,3,2,1,2,3,4,7);
  34.    Stuff := (4 => 12, 5 => 13, 6 => 7, 7 => 1, 8 => 11);
  35.  
  36.    Total := Sum_Up(My_List);
  37.    Total := Sum_Up(Stuff);
  38. end Summer;
  39.  
  40.  
  41.  
  42.  
  43. -- Result of Execution
  44.  
  45. -- The sum of the numbers is    32
  46. -- The sum of the numbers is    44
  47.  
  48.