SumThem



Program SumThem;
{ A simple program with a procedure that takes parameters: }

{ set up a type that defines an array of 5 elements each of 
  type real. This way we don’t have to repeatedly type 
   array[1..5] of real.
}

type
   tp_Array5 = array[1..5] of real;

var
   nums : tp_Array5;
   the_sum : real;

{ ----------------------------------------------------------------
  CalcSum
  Calculate the sum of the numbers in num_list[]
  ---------------------------------------------------------------- }

procedure CalcSum(num_list : tp_Array5; var sum : real);
var
   i : integer;    { i is a local variable of CalcSum }

begin
   sum := 0.0;   { initialize sum to be zero }

   i := 1;
   while (i <= 5) do
   begin
      sum := sum + num_list[i];
      i := i + 1;
   end; { while }

end; { CalcSum }

{ ----------------------------------------------------------------
  main program begins
  ---------------------------------------------------------------- }

begin
   nums[1] := 50.0;
   nums[2] := 56.7;
   nums[3] := 42.9;
   nums[4] := 69.42;
   nums[5] := 23.0;

   CalcSum(nums, the_sum);

   writeln(‘The sum of the numbers is: ‘, the_sum:0:3);

end. { main program }