home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / ipo-101.zip / Samples.zip / ADD.PAS next >
Pascal/Delphi Source File  |  1998-03-31  |  719b  |  26 lines

  1. program add(output);
  2. (*
  3. ** This sample program adds up all the program arguments
  4. ** and prints out the sum
  5. *)
  6. var
  7.    sum, (* Stores the sum *)
  8.    i,   (* Counts the program arguments *)
  9.    x,   (* Stores the converted program arguments *)
  10.    err  (* Indicates whether or not there was an error *)
  11.    : integer;
  12. begin
  13.    sum := 0;    (* initiaze the sum *)
  14.    for i := 1 to paramcount do
  15.       begin
  16.          val(paramstr(i), x, err);   (* Convert program agument into an integer *)
  17.          if err <> 0 then
  18.             begin
  19.                writeln(paramstr(i), ' is not a valid integer');
  20.                halt
  21.             end;
  22.          sum := sum + x
  23.       end;
  24.    writeln('Sum is ', sum)
  25. end.
  26.