home *** CD-ROM | disk | FTP | other *** search
- -- Chapter 19 - Program 1
- with Text_IO;
- use Text_IO;
-
- procedure Summer is
-
- package Int_IO is new Text_IO.Integer_IO(INTEGER);
- use Int_IO;
-
- type MY_ARRAY is array (POSITIVE range <>) of INTEGER;
-
- Dummy1 : constant MY_ARRAY := (27,14,13,33);
- Dummy2 : constant MY_ARRAY := (112 => 27, 113 => 14,
- 114 => 13, 115 => 33);
-
- My_List : MY_ARRAY(1..12);
- Stuff : MY_ARRAY(4..8) := (12,13,7,11,125);
- Total : INTEGER;
-
- function Sum_Up(In_Array : MY_ARRAY) return INTEGER is
- Sum : INTEGER := 0;
- begin
- for Index in In_Array'FIRST..In_Array'LAST loop
- Sum := Sum + In_Array(Index);
- end loop;
- Put("The sum of the numbers is");
- Put(Sum);
- New_Line;
- return Sum;
- end Sum_Up;
-
- begin
- My_List := (0,1,2,3,4,3,2,1,2,3,4,7);
- Stuff := (4 => 12, 5 => 13, 6 => 7, 7 => 1, 8 => 11);
-
- Total := Sum_Up(My_List);
- Total := Sum_Up(Stuff);
- end Summer;
-
-
-
-
- -- Result of Execution
-
- -- The sum of the numbers is 32
- -- The sum of the numbers is 44
-
-