Miles Per Gallon

This file is part of and Timex Sinclair Public Domain Library Tape 1001. Download the collection to get this file.
Date: 198x
Type: Program
Platform(s): TS 1000
Tags: Finance, Home

This program calculates and prints a monthly miles-per-gallon report for a car, taking inputs for miles driven, gallons used, cost per gallon, business miles, and IRS mileage allowance. It computes MPG, total fuel cost, and a tax deduction figure, then sends a formatted summary to a printer via LPRINT. An optional branch handles fuel and oil additive costs, calculating per-use cost by dividing bottle price by a fixed 12-use assumption for gas additives and by oil-change interval in miles for oil additives.


Program Analysis

Program Structure

The program is divided into a clear sequence of functional blocks:

  1. Lines 10–50: Title screen with a brief delay loop (FOR T=1 TO 200).
  2. Lines 60–184: Main input section — month label, miles, gallons, cost per gallon, business miles, IRS allowance. Core calculations (MPG, TCG, DED) are performed here.
  3. Lines 185–189: Branch point asking whether additives are used; “Y” routes to the additive subroutine at line 400, “N” falls through to line 190.
  4. Lines 190–270: LPRINT block producing the printed monthly report.
  5. Lines 275–395: Secondary oil-additive question and cost summary via LPRINT, with two branches (additive used or not).
  6. Lines 400–690: Subroutine for additive cost calculations — gas additive (line 500) and oil additive (line 600).
  7. Lines 1000–1060: Reprint option, housekeeping (CLEAR), and auto-run SAVE.

Calculations

VariableFormulaMeaning
MPGM/GMiles per gallon
TCGC*GTotal cost of fuel
DEDA*RIRS mileage deduction
COAA/BB (BB=12)Gas additive cost per use (assumes 12 uses per bottle)
DDG/12.5Number of gas additive doses used
CMDD*COMonthly gas additive cost
MOCC/EEOil additive cost per mile
MTMO*MMonthly oil additive cost
TCACM+MTTotal additive cost (both types)
TOCTCA+TCGTotal operating cost with both additives
TBCM+TCGTotal operating cost with gas additive only

Control Flow and Notable Idioms

The program uses paired IF … THEN GOTO / IF … THEN GOSUB constructs for all branching — there is no ELSE. The additive section at line 400 is entered via GOSUB 400 (line 188) but returns indirectly: rather than RETURN, every path eventually executes GOTO 190 (lines 470, 690), effectively jumping back into the main body. This means the subroutine call stack is never unwound cleanly, and the GOSUB return address is silently abandoned.

Input echoing is performed after every INPUT statement (e.g., lines 101, 131, 162) with a bare PRINT of the variable, a common technique on systems where the input cursor does not automatically leave a clear line.

Bugs and Anomalies

  • Variable reuse — A: A is first used at line 172 for business miles driven, then reused as the loop variable in the delay FOR loop — except that loop uses T, so this collision does not actually occur. However, A is later overwritten implicitly if any loop used it; as written it is safe.
  • Undefined CM on oil-only path: At line 350, if the user selected no gas additive but went through the oil-additive path, CM is printed as the total additive cost. But if only an oil additive was used (path via line 600 then 190 then 280 then 295→350), CM will be 0 or uninitialized rather than MT. The oil-additive cost MT is computed at line 675 but never added into CM on this path — only TCA=CM+MT at line 300 handles that case.
  • Logic gap at lines 188–189: If the user enters neither “Y” nor “N” at line 185, neither branch fires and execution falls through to line 190 silently, skipping any prompt for retry.
  • Lines 1040–1060: After the reprint loop, CLEAR is called followed by SAVE and RUN. The SAVE filename contains an inverse-video digit acting as an auto-run flag. RUN at line 1060 restarts the program, making this block reachable only if the user chose not to reprint.

Printed Output

The report sent to the printer via LPRINT includes the month label, miles driven, gallons used, MPG, cost per gallon, total fuel cost, business miles, and the IRS deduction. Additive costs and total operating cost are appended depending on the user’s choices. Blank LPRINT lines are used throughout for spacing, a standard technique for thermal printer formatting.

Display Formatting

The title and introductory screens use inverse-video characters (rendered in the source as %M%P%G etc.) to produce highlighted banner text. This is a purely cosmetic effect achieved without any POKE or machine code — just the inverse character codes built into the character set.

Content

Appears On

Assembled by Tim Ward from many sources. Contains programs 10001 – 10050.

Related Products

Related Articles

Related Content

Image Gallery

Miles Per Gallon

Source Code

  10 CLS 
  20 PRINT "%M%P%G% %C%A%L%C%U%L%A%T%O%R"
  30 FOR T=1 TO 200
  40 NEXT T
  50 CLS 
  60 PRINT "%T%H%I%S% %P%R%O%G%R%A%M% %D%E%T%E%R%M%I%N%E%S"
  70 PRINT "%T%H%E% %M%P%G% %Y%O%U%R% %C%A%R% %G%E%T%S."
  71 PRINT 
  72 PRINT "ENTER THE MONTH OF REPORT"
  73 INPUT Y$
  74 PRINT Y$
  75 PRINT 
  76 PRINT "THIS REPORT IS FOR THE MONTH OF ";Y$
  77 PRINT 
  80 PRINT "HOW MANY MILES DID YOU DRIVE"
  90 PRINT "DURING THE PAST 5 FILL-UPS?"
 100 INPUT M
 101 PRINT M
 102 PRINT 
 110 PRINT "HOW MANY GALLONS OF GAS DID YOU"
 120 PRINT "USE IN THE PAST 5 FILL-UPS?"
 130 INPUT G
 131 PRINT G
 132 PRINT 
 140 LET MPG=M/G
 150 PRINT "YOU HAVE BEEN GETTING ";MPG
 151 PRINT 
 160 PRINT "ENTER COST PER GALLON"
 161 INPUT C
 162 PRINT C
 163 LET TCG=C*G
 164 PRINT "YOUR MONTHLY COST IS $ ";TCG
 170 PRINT 
 171 PRINT "ENTER BUS MILES DRIVEN"
 172 INPUT A
 173 PRINT A
 174 PRINT "ENTER IRS MILEAGE ALLOWANCE"
 175 INPUT R
 176 PRINT R
 180 LET DED=A*R
 181 PRINT "YOUR MONTHLY CAR DEDUCTION IS $ ";DED
 185 PRINT "DO YOU USE ADDITIVES?ENTER Y OR N"
 186 INPUT A$
 188 IF A$="Y" THEN GOSUB 400
 189 IF A$="N" THEN GOTO 190
 190 LPRINT "%M%P%G% %C%A%L%C%U%L%A%T%O%R"
 191 LPRINT 
 200 LPRINT Y$
 201 LPRINT 
 210 LPRINT "YOU DROVE ";M;" MILES"
 211 LPRINT 
 220 LPRINT "YOU USED ";G;" GALLONS"
 225 LPRINT 
 230 LPRINT "YOU HAVE BEEN GETTING ";MPG;" MILES PER GALLON"
 235 LPRINT 
 240 LPRINT "YOUR COST PER GALLON IS ";C
 245 LPRINT 
 250 LPRINT "YOUR TOTAL FUEL COST FOR ";Y$;" WAS ";TCG
 255 LPRINT 
 260 LPRINT "YOUR BUS MILES DRIVEN WERE ";A;" MILES"
 265 LPRINT 
 270 LPRINT "YOUR MONTHLY CAR DEDUCTION IS ";DED
 275 CLS 
 280 PRINT "DID YOU USE OIL ADDITIVE? ENTER Y OR N"
 284 INPUT T$
 290 IF T$="Y" THEN GOTO 300
 295 IF T$="N" THEN GOTO 350
 300 LET TCA=CM+MT
 310 LPRINT "TOTAL COST OF ADDITIVES IS ";TCA
 320 LPRINT 
 325 LET TOC=TCA+TCG
 330 LPRINT "TOTAL OPERATING COST FOR THE MONTH OF ";Y$;" IS ";TOC
 340 GOTO 1000
 350 LPRINT "TOTAL COST OF ADDITIVES IS ";CM
 355 LPRINT 
 358 LET TB=CM+TCG
 360 LPRINT "TOTAL OPERATING COST FOR THE MONTH OF ";Y$;" IS ";TB
 395 GOTO 1000
 400 CLS 
 410 PRINT "DO YOU USE GAS ADDITIVE? ENTER Y OR N"
 420 INPUT B$
 430 IF B$="Y" THEN GOTO 500
 435 IF B$="N" THEN GOTO 440
 440 PRINT "DO YOU USE AN OIL ADDITIVE? ENTER Y OR N"
 450 INPUT O$
 460 IF O$="Y" THEN GOTO 600
 465 IF O$="N" THEN GOTO 470
 470 GOTO 190
 500 CLS 
 510 PRINT "ENTER COST PER BOTTLE?"
 520 INPUT AA
 530 PRINT AA
 550 LET BB=12
 565 LET CO=AA/BB
 576 LET DD=G/12.5
 577 LET CM=DD*CO
 580 PRINT "YOUR GAS ADDITIVE COST WAS ";CM
 585 GOTO 440
 600 CLS 
 610 PRINT "OIL ADDITIVE COST PER BOTTLE?"
 620 INPUT CC
 630 PRINT CC
 640 PRINT "HOW OFTEN DO YOU CHANGE OIL (IN MILES)?"
 650 INPUT EE
 660 PRINT EE
 670 LET MO=CC/EE
 675 LET MT=MO*M
 680 PRINT "YOUR OIL ADDITIVE COST FOR THE MONTH OF ";Y$;" WAS ";MT
 690 GOTO 190
 1000 PRINT "WOULD YOU LIKE ANOTHER COPY? ENTER Y OR N"
 1010 INPUT L$
 1020 IF L$="Y" THEN GOTO 190
 1030 IF L$="N" THEN STOP 
 1040 CLEAR 
 1050 SAVE "1003%1"
 1060 RUN 

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.

People

No people associated with this content.

Scroll to Top