home *** CD-ROM | disk | FTP | other *** search
/ CP/M / CPM_CDROM.iso / simtel / sigm / vols000 / vol069 / mileage.pas < prev    next >
Pascal/Delphi Source File  |  1984-04-29  |  2KB  |  63 lines

  1. (*===================================================
  2.  
  3. PROGRAM TITLE:  Mileage Statistics
  4.  
  5. AUTHOR:        William E. Lewis
  6.  
  7. ADAPATION BY:    Charlie Foster, Aug 1981
  8.  
  9. PROGRAM SUMMARY:
  10.  
  11.     This program processes Automobile odometer
  12. readings and gas consumptions. It has been adapated
  13. for Pascal/Z. The program terminates after the number
  14. of odometer readings have been processed. It computes
  15. Average miles per gallon, average miles between refills
  16. and average gallons between refills.
  17.  
  18. ===================================================*)
  19.  
  20. PROGRAM MileageStatistics;
  21.  
  22. VAR
  23.   TotalMiles, TotalGallons,
  24.   NumReadings, CurrentReading,
  25.   NextOdometerValue, OdometerValue,
  26.   GallonsAdded                 : INTEGER;
  27.  
  28.   MilesGallon, AvgMilesGallon,
  29.   AvMileRefill, AvgGallonsRefill   : REAL;
  30.  
  31. BEGIN
  32.   TotalMiles    := 0;
  33.   TotalGallons    := 0;
  34.   WRITE ('Please enter the number of reading you want--> ');
  35.   READLN (NumReadings);
  36.   WRITELN;  
  37.   WRITE ('Please enter the first odometer reading--> ');
  38.   READLN (OdometerValue);
  39.   WRITELN;
  40.   WRITELN ('Now enter the NEXT odometer reading and number ');
  41.   WRITELN ('of gallons added. Do this ',NumReadings:2,'  times.');
  42.   WRITELN (' ':20,'============MILES PER GALLON============');
  43.   FOR CurrentReading := 1 TO NumReadings DO
  44.     BEGIN
  45.     READ (NextOdometerValue, GallonsAdded);
  46.     MilesGallon := (NextOdometerValue-OdometerValue) /
  47.             Gallonsadded;
  48.     WRITELN (' ':37,MilesGallon);
  49.     TotalMiles := TotalMiles + (NextOdometerValue-
  50.             OdometerValues);
  51.     TotalGallons := TotalGallons + GallonsAdded;
  52.     OdometerValue := NextOdometerValue;
  53.     END;    (* the FOR loop *)
  54.   WRITELN (' ':20,'=======================================');
  55.   AvgMilesGallon := TotalMiles / TotalGallons;
  56.   WRITELN ('Your average miles per gallon =       ',AvgMilesGallon);
  57.   AvMileRefill := TotalMiles / NumReadings;
  58.   WRITELN ('Your average miles per refill =       ',AvMileRefill);
  59.   AvgGallonsRefill := TotalGallons / NumReadings;
  60.   WRITELN ('Your average gallons per refill =     ',AvgGallonsRefill);
  61.  
  62. END.
  63.