
PROGRAM Temps2 (Input,Output,TempFile);

CONST
   Low = '.';          (* Symbol for low temp *)
   Aver = '-';         (* Symbol for average temp *)
   High = '*';         (* Symbol for high temp *)
   Bottom = -30;       (* Bottom of chart in centigrade *)
   Top = 50;           (* Top of chart in centigrade *)

VAR
   TMin,               (* Overall minimum temperature *)
   TMax,               (* Overall maximum temperature *)
   Min,                (* Daily minimum *)
   Max,                (* Daily maximum *)
   Average : Integer;  (* Daily average *)
   Count : Integer;    (* Counter of symbols dsiplayed *)
   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 produces a histogram of the minimum, maximum, and average');
   Writeln('temperatures during the period covered by the file.');
   Writeln('It also 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);

   (* Display scale of histogram *)
   Writeln;
   Writeln('                              DEGREES CENTIGRADE');
   Write('-30      -20       -10        0        10');
   Write('        20        30        40       50');
   Write('|----|----|----|----|----|----|----|----|');
   Write('----|----|----|----|----|----|----|----');

   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 *)

      Average := (Min + Max) DIV 2;     (* Daily average temp *)

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

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

      (* Display low symbol from bottom of scale to Min temp *)
      Count := Bottom;
      WHILE (Count <= Min) AND (Count <= Top) DO
       Begin
         Write(Low);
         Count := Count + 1;
       End;

      (* Display average symbol from Min temp to Average temp *)
      WHILE (Count <= Average) AND (Count <= Top) DO
       Begin
         Write(Aver);
         Count := Count + 1;
       End;

      (* Display high symbol from Average temp to Max temp *)
      WHILE (Count <= Max) AND (Count <= Top) DO
       Begin
         Write(High);
         Count := Count + 1;
       End;

      Writeln;  (* Next day's symbols on next output line *)
    End;

   (* Overall coldest and hottest temps *)
   Writeln;
   Writeln;
   Writeln('Coldest temperature was: ',TMin);
   Writeln('Hottest temperature was: ',TMax);
END.


















