PROGRAM Mileage (Input,Output,InData,OutData);

(* David Wills
   CMIS 102  University of Maryland
   SHAPE  Term 4  1991
   Turbo Pascal 5.5  *)

(* This program reads from a file the number of liters of gasoline
a car consumed and the number of kilometers driven.  It computes
the miles per gallon and writes that to another file.  *)

CONST
   LPG = 3.7853;    (* Liters in one gallon *)
   KPM = 1.609;     (* Kilometers in one mile *)

VAR
   InData, OutData : Text;    (* Input and output files, respectively *)
   InFileName, OutFileName : String; (* Names of input and output files,
                                        respectively.  Input by user *)
   Liters,                    (* Input from file *)
   Gallons,
   Kilometers,                (* Input from file *)
   Miles,
   MPG         : Real;

BEGIN
   (* Get input file name from user.  Prepare file for reading *)
   Write('Name of input file containing liters and kilometers: ');
   Readln(InFileName);
   Assign(InData,InFileName);
   Reset(InData);

   (* Get output file name from user.  Prepare file for writing *)
   Write('Name of output file to contain miles per gallon: ');
   Readln(OutFileName);
   Assign(OutData,OutFileName);
   Rewrite(OutData);

   (* Input data from file *)
   Readln(InData,Liters);
   Writeln('Liters used are: ',Liters:6:2);
   Readln(InData,Kilometers);
   Writeln('Kilometers driven are: ',Kilometers:6:2);

   (* Convert data to English, compute mileage, write to file *)
   Gallons := Liters / LPG;       (* Convert liters to gallons *)
   Miles := Kilometers / KPM;     (* Convert kilometers to miles *)
   MPG := Miles / Gallons;        (* Compute mileage *)
   Writeln(OutData,'Mileage in MPG = ',MPG:6:2);  (* Write to file *)
   Writeln('Mileage in MPG = ',MPG:6:2);
END.