
PROGRAM Temps1 (Input,Output,TempFile);

VAR
   TMin,               (* Overall minimum temperature *)
   TMax,               (* Overall maximum temperature *)
   Min,                (* Daily minimum *)
   Max : Integer;      (* Daily maximum *)
   FileName : String;  (* Name of file, user input *)
   TempFile : Text;    (* File of daily minimum and maximum temp. pairs *)

BEGIN
   Writeln('This program reads a file of minimum and maximum daily temp',
           'eratures.');
   Writeln('It determines the coldest day and the hottest day.');
   Writeln;
   Write('Enter the name of the file of daily temperatures: ');
   Readln(FileName);
   Assign(TempFile,FileName);
   Reset(TempFile);

   TMin := 200;     (* Dummy values for first comparison *)
   TMax := -200;

   WHILE NOT EOF(TempFile) DO           (* until end of file *)
    Begin
      Readln(TempFile,Min,Max);         (* Read a pair of daily temps *)

      IF Min < TMin THEN         (* Is this a new overall minimum? *)
         TMin := Min;

      IF Max > TMax THEN         (* Is this a new overall maximum? *)
         TMax := Max;
    End;

   Writeln;
   Writeln('Coldest temperature was: ',TMin);
   Writeln('Hottest temperature was: ',TMax);
END.


















