An Ohm’s law calculator. Enter the values you know for voltage, current, resistance and power, and 0 for the ones you don’t; after two values the program calculates and shows the other two. Press any key for another calculation, or BREAK to stop. Line 1 saves the program, so start it with GOTO 2 after typing it in.
As printed, line 390 multiplies by R where it should divide, so with voltage and resistance as the known values the power comes out wrong (12 V and 6 ohms give 864 W instead of 24 W). Change (V**2)*R to (V**2)/R to fix it. The article shows how to make the title REM line 0.
Published in Syntax December 1983 (Ohm’s ZXlaw).
Source Code
0 REM OHMS ZXLAW (C) 1982 BRAD HOGG BOX 1814 SWAN RIVER, MB CANADA R0L 1Z0
1 SAVE "OHM"
2 SLOW
10 CLS
20 LET V=0
30 LET I=0
40 LET R=0
50 LET P=0
60 LET C=3
70 PRINT " OHMS LAW INPUT KNOWN VALUES V,I,R,P (0 IF UNKNOWN)"
80 PRINT AT C,0;"VOLTAGE (V)=";
90 INPUT V
100 IF V THEN LET C=C+1
110 PRINT V;" V"
120 PRINT AT C,0;" "
130 PRINT AT C,0;"CURRENT (I)=";
140 INPUT I
150 IF I THEN LET C=C+1
160 PRINT I;" A"
170 IF V AND I THEN GOTO 290
180 PRINT AT C,0;" "
190 PRINT AT C,0;"RESISTANCE (R)=";
200 INPUT R
210 IF R THEN LET C=C+1
220 PRINT R;" OHMS"
230 IF V AND R OR I AND R THEN GOTO 290
240 PRINT AT C,0;" "
250 PRINT AT C,0;"POWER (P)=";
260 INPUT P
265 PRINT P;" W"
270 IF P THEN LET C=C+1
290 IF NOT V OR NOT I THEN GOTO 320
300 PRINT "POWER (P)=";V*I;" W"
310 PRINT "RESISTANCE (R)=";V/I;" OHMS"
320 IF NOT P OR NOT R THEN GOTO 350
330 PRINT "CURRENT (I)=";SQR (P/R);" A"
340 PRINT "VOLTAGE (V)=";SQR (P*R);" V"
350 IF NOT P OR NOT I THEN GOTO 380
360 PRINT "VOLTAGE (V)=";P/I;" V"
370 PRINT "RESISTANCE (R)=";P/(I**2);" OHMS"
380 IF NOT R OR NOT V THEN GOTO 410
390 PRINT "POWER (P)=";(V**2)*R;" W"
400 PRINT "CURRENT (I)=";V/R;" A"
410 IF NOT I OR NOT R THEN GOTO 440
420 PRINT "POWER (P)=";(I**2)*R;" W"
430 PRINT "VOLTAGE (V)=";I*R;" V"
440 IF NOT V OR NOT P THEN GOTO 470
450 PRINT "RESISTANCE (R)=";(V**2)/P;" OHMS"
460 PRINT "CURRENT (I)=";P/V;" A"
470 PRINT AT 21,0;"PRESS ANY KEY TO CONTINUE"
490 IF INKEY$="" THEN GOTO 490
500 RUN 2Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.

