Ohm’s Law

Date: 198x
Type: Program
Platform(s): TS 2068

This program is an Ohm’s Law calculator that derives all four electrical quantities — voltage (V), current (I), resistance (R), and power (P) — from any two known values entered by the user. The user inputs known quantities and enters 0 for unknowns; the program then applies whichever of the six possible two-variable formulas can be satisfied. All standard relationships are covered: P=VI, R=V/I, I=√(P/R), V=√(PR), V=P/I, R=P/I², P=V²/R (note a bug here), I=V/R, P=I²R, V=IR, R=V²/P, and I=P/V. The program is saved with an auto-run LINE 1 directive so it launches immediately on load.


Program Structure

The program is organized into three broad phases:

  1. Initialisation (lines 10–175): REM banner, variable zeroing, and prompt display.
  2. Input collection (lines 180–365): Sequential prompts for V, I, R, and P, with early exits via GO TO 390 once enough known values have been entered.
  3. Formula evaluation (lines 390–570): Six guarded blocks, each checking whether two specific variables are non-zero before printing the derived quantities.

Input / Early-Exit Logic

The program uses truthiness of numeric variables as boolean flags: a value of 0 is “false” (unknown) and any non-zero value is “true” (known). After collecting V and I, line 270 tests IF V AND I THEN GO TO 390; if both are known no further input is needed. Line 330 similarly skips the power prompt when either V+R or I+R are both known. This means a user can supply exactly two values and the program proceeds to the output section.

Formula Coverage

LinesKnown pairDerived quantities
390–410V, IP = V×I, R = V/I
420–440P, RI = √(P/R), V = √(P×R)
450–470P, IV = P/I, R = P/I²
480–500R, VP = V²×R (bug — see below), I = V/R
510–530I, RP = I²×R, V = I×R
540–560V, PR = V²/P, I = P/V

Notable Bug

Line 490 reads PRINT "Power (P)=";(V^2)*R;" W". The correct formula for power given voltage and resistance is P = V²/R, not V²×R. The multiplication sign should be a division sign. The complementary formula on line 500 (I = V/R) is correct, so this is an isolated arithmetic error rather than a structural fault.

Key BASIC Idioms

  • Zero-as-false guard: IF NOT V OR NOT I THEN GO TO 450 — each output block is skipped unless both required variables are non-zero, neatly encoding “do we have enough information?”
  • Compound boolean in input phase: Line 330 uses IF V AND R OR I AND R to check two sufficient pairs simultaneously before prompting for P.
  • Inline echo: After each INPUT the program immediately PRINTs the accepted value with its unit (lines 210, 260, 320, 365), confirming the entry to the user.
  • Auto-run save: Line 9998 uses SAVE "OHM'S LAW" LINE 1 to embed the start line in the tape header, so the program runs automatically on LOAD.
  • Exponentiation notation: The caret ^ is used for powers (e.g., I^2, V^2); line 475 even includes a REM explaining this for less-experienced users.

Variable Initialisation

Lines 120–150 explicitly set v, I, R, and P to 0. Note that line 120 uses lowercase v while the rest of the program uses uppercase V; on this platform variable names are case-sensitive, so v and V are distinct variables. The initialisation of v at line 120 is therefore redundant with respect to V as used in the input and calculation sections, though in practice both will default to 0 anyway.

Program Flow Anomaly

Line 50 prints the title banner before line 100 clears the screen (CLS), so the title appears only briefly and is immediately erased. This appears to be an oversight; the banner in the REM block (lines 10–21) is never actually displayed to the user, and the PRINT at line 50 is functionally invisible.

Content

Appears On

Capital Area Timex Sinclair User Group’s Library Tape.
Library tape of the Indiana Sinclair Timex User’s Group.

Related Products

Related Articles

Related Content

Image Gallery

Ohm’s Law

Source Code

   10 REM //////////////////////
   12 REM /                    /
   13 REM /      OHM'S LAW     /
   20 REM /                    /
   21 REM //////////////////////
   50 PRINT "  OHM'S LAW  "
  100 CLS 
  120 LET v=0
  130 LET I=0
  140 LET R=0
  150 LET P=0
  170 PRINT "Input known values"
  175 PRINT "  0 If unknown"
  176 PRINT 
  177 PRINT 
  178 PRINT 
  180 PRINT ;"voltage     (V)=";
  190 INPUT V
  210 PRINT V;" V"
  230 PRINT ;"Current     (I)=";
  240 INPUT I
  260 PRINT I;" A"
  270 IF V AND I THEN GO TO 390
  290 PRINT ;"Resistance  (R)=";
  300 INPUT R
  320 PRINT R;" Ohms"
  330 IF V AND R OR I AND R THEN GO TO 390
  350 PRINT ;"Power       (P)=";
  360 INPUT P
  365 PRINT P;" W"
  390 IF NOT V OR NOT I THEN GO TO 420
  400 PRINT "Power        (P)=";V*I;" W"
  410 PRINT "Resistance   (R)=";V/I;" Ohms"
  420 IF NOT P OR NOT R THEN GO TO 450
  430 PRINT "Current      (I)=";SQR (P/R);" A"
  440 PRINT "Voltage      (V)=";SQR (P*R);" V"
  450 IF NOT P OR NOT I THEN GO TO 480
  460 PRINT "Voltage      (V)=";P/I;" V"
  470 PRINT "Resistance   (R)=";P/(I^2);" Ohms"
  475 REM ^ = raised to the power of
  480 IF NOT R OR NOT V THEN GO TO 510
  490 PRINT "Power        (P)=";(V^2)*R;" W"
  500 PRINT "Current      (I)=";V/R;" A"
  510 IF NOT I OR NOT R THEN GO TO 540
  520 PRINT "Power        (P)=";(I^2)*R;" W"
  530 PRINT "Voltage      (V)=";I*R;" V"
  540 IF NOT V OR NOT P THEN GO TO 570
  550 PRINT "Resistance   (R)=";(V^2)/P;" Ohms"
  560 PRINT "Current      (I)=";P/V;" A"
  570 PRINT 
  571 PRINT 
  572 PRINT 
  573 PRINT 
 1000 STOP 
 9998 SAVE "OHM'S LAW" LINE 1

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

People

No people associated with this content.

Scroll to Top