Trigonometry

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

This program is a trigonometry calculator covering all nine fundamental right-triangle formulae using sine, cosine, and tangent. A menu screen (lines 10–150) displays all nine formula options (A through I) alongside ASCII block-graphic representations of a right triangle drawn with the ▙ character, with option J providing a STOP. Each chosen formula branches to a dedicated input-and-calculation routine that prompts the user for the required known values, converts degrees to radians using the PI constant where needed, applies the appropriate trig function or its inverse (ASN, ACS, ATN), and displays the result before looping back to the menu. The degree/radian conversion pattern `S*PI/180` and its inverse `*180/PI` appears consistently throughout all nine calculation blocks.


Program Analysis

Program Structure

The program is divided into three logical zones:

  1. Menu display (lines 10–150): Clears the screen and prints the formula menu with block-graphic triangle diagrams and labelled options A–J.
  2. Input dispatcher (lines 800–910): Reads a single character into B$ and branches to the appropriate calculation routine, or STOPs on “J”. Line 910 re-prompts on any out-of-range character.
  3. Calculation routines (lines 1100–2810): Nine self-contained blocks, each CLS-ing, prompting for two known values, computing the unknown, displaying the result, waiting for NEWLINE, then GOTO 10 to return to the menu.

Lines 2820–2840 form a save/run footer: CLEAR, SAVE "1025%7" (the %7 being an inverse “7” triggering auto-run), followed by RUN.

Formula Coverage

OptionFormulaUnknowns SoughtKey Operation
ASIN = OPP/HYPAngle (degrees)ASN(O/H)*180/PI
BOPP = SIN*HYPOPPSIN(S*PI/180)*H
CHYP = OPP/SINHYPO/SIN(S*PI/180)
DCOS = ADJ/HYPAngle (degrees)ACS(A/H)*180/PI
EADJ = COS*HYPADJCOS(C*PI/180)*H
FHYP = ADJ/COSHYPA/COS(C*PI/180)
GTAN = OPP/ADJAngle (degrees)ATN(O/A)*180/PI
HOPP = TAN*ADJOPPTAN(T*PI/180)*A
IADJ = OPP/TANADJO/TAN(T*PI/180)

Degree/Radian Conversion

All forward trig calls (options B, C, E, F, H, I) require the user to enter an angle in degrees. The program consistently converts with S*PI/180 (or C*PI/180, T*PI/180) before passing to SIN, COS, or TAN. Inverse results from ASN, ACS, and ATN (options A, D, G) are converted back to degrees with *180/PI. This is correct and consistent throughout.

Notable Techniques

  • Block-graphic triangle diagrams: The menu uses the \.:` escape (▙) repeated to sketch right-triangle silhouettes, labelling hypotenuse, opposite, adjacent, and the relevant trig ratio direction inline within PRINT statements.

  • Inverse video label: Line 140 prints %S%T%O%P (inverse-video “STOP”) for option J, making it visually distinct from the formula labels.

  • Single-character dispatch: The dispatcher at lines 810–900 uses nine sequential IF … THEN GOTO lines rather than computed GOTO, which is typical of Sinclair BASIC where ON … GOTO is not available.

  • “Press NEWLINE to continue” idiom: Each calculation block uses INPUT A$ (line x10) solely as a pause mechanism, accepting any input — a common Sinclair BASIC substitute for a dedicated key-wait.

  • Variable reuse: A$ is used as the “press NEWLINE” sink in every calculation block (lines 1210, 1400, 1600, etc.), while B$ is reserved for the menu selection. Numeric variables are reused across routines without issue because each block reassigns before use.

Bugs and Anomalies

  • Misleading prompts for forward trig inputs: In routines B, C, E, F, H, and I, the echo line prints e.g. "SIN= ";S;" DEGS" (line 1330), but SIN, COS, and TAN are dimensionless ratios — the user is entering an angle in degrees, not a ratio. The label " DEGS" is technically correct for the angle, but the variable name S (named after SIN) and the prompt "INPUT SIN" are potentially confusing.
  • No input validation: There is no guard against division by zero (e.g., entering HYP=0 for option A, or ADJ=0 for option G), which would cause a runtime error.
  • Line 910 range check: IF B$<"A" OR B$>"J" THEN GOTO 800 correctly rejects characters outside A–J but does not handle the letters K–Z entered as lower-case or multi-character strings, since the earlier checks only test exact uppercase equality. Lower-case entries would fall through to line 910 and re-prompt correctly.

Content

Appears On

Assembled by Tim Ward from many sources. Contains programs 10252 – 10293.

Related Products

Related Articles

Related Content

Image Gallery

Trigonometry

Source Code

  10 CLS 
  20 PRINT AT 1,8;"**TRIGONOMETRY**"
  30 PRINT AT 4,0;"INPUT";TAB 8;"FORMULAE"
  40 PRINT AT 6,2;"A";TAB 7;"SIN=OPP/HYP";TAB 27;".:"
  50 PRINT AT 7,2;"B";TAB 7;"OPP=SIN*HYP";TAB 22;"HYP .:%  OPP"
  60 PRINT AT 8,2;"C";TAB 7;"HYP=OPP/SIN  SIN->.:% % "
  70 PRINT AT 10,2;"D";TAB 7;"COS=ADJ/HYP";TAB 27;".:"
  80 PRINT AT 11,2;"E";TAB 7;"ADJ=COS*HYP";TAB 22;"HYP .:% "
  90 PRINT AT 12,2;"F";TAB 7;"HYP=ADJ/COS";TAB 20;"COS->.:% % "
 100 PRINT TAB 25;"ADJ"
 110 PRINT AT 15,2;"G";TAB 7;"TAN=OPP/ADJ";TAB 27;".:"
 120 PRINT AT 16,2;"H";TAB 7;"OPP=TAN*ADJ";TAB 26;".:%  OPP"
 130 PRINT AT 17,2;"I";TAB 7;"ADJ=OPP/TAN";TAB 20;"TAN->.:% % "
 140 PRINT TAB 25;"ADJ";AT 19,2;"J";TAB 7;"%S%T%O%P"
 150 PRINT AT 21,0;"INPUT: REQUIRED FORMULAE(A TO J)"
 800 INPUT B$
 810 IF B$="A" THEN GOTO 1100
 820 IF B$="B" THEN GOTO 1300
 830 IF B$="C" THEN GOTO 1500
 840 IF B$="D" THEN GOTO 1700
 850 IF B$="E" THEN GOTO 1900
 860 IF B$="F" THEN GOTO 2100
 870 IF B$="G" THEN GOTO 2300
 880 IF B$="H" THEN GOTO 2500
 890 IF B$="I" THEN GOTO 2700
 900 IF B$="J" THEN STOP 
 910 IF B$<"A" OR B$>"J" THEN GOTO 800
 1100 CLS 
 1110 PRINT AT 2,2;"INPUT OPP"
 1120 INPUT O
 1130 PRINT AT 2,15;"OPP= ";O
 1140 PRINT AT 4,2;"INPUT HYP"
 1150 INPUT H
 1160 PRINT AT 4,15;"HYP= ";H
 1170 LET S=O/H
 1180 LET X=ASN S*180/PI
 1190 PRINT AT 6,5;"ANGLE= ";X;" DEGS"
 1200 PRINT AT 10,3;"PRESS NEWLINE TO CONTINUE"
 1210 INPUT A$
 1220 GOTO 10
 1300 CLS 
 1310 PRINT AT 2,2;"INPUT SIN"
 1320 INPUT S
 1330 PRINT AT 2,15;"SIN= ";S;" DEGS"
 1340 PRINT AT 4,2;"INPUT HYP"
 1350 INPUT H
 1360 PRINT AT 4,15;"HYP= ";H
 1370 LET O=(SIN (S*PI/180))*H
 1380 PRINT AT 6,5;"OPP= ";O
 1390 PRINT AT 10,3;"PRESS NEWLINE TO CONTINUE"
 1400 INPUT A$
 1410 GOTO 10
 1500 CLS 
 1510 PRINT AT 2,2;"INPUT OPP"
 1520 INPUT O
 1530 PRINT AT 2,15;"OPP= ";O
 1540 PRINT AT 4,2;"INPUT SIN"
 1550 INPUT S
 1560 PRINT AT 4,15;"SIN= ";S;" DEGS"
 1570 LET H=O/(SIN (S*PI/180))
 1580 PRINT AT 6,5;"HYP= ";H
 1590 PRINT AT 10,3;"PRESS NEWLINE TO CONTINUE"
 1600 INPUT A$
 1610 GOTO 10
 1700 CLS 
 1710 PRINT AT 2,2;"INPUT ADJ"
 1720 INPUT A
 1730 PRINT AT 2,15;"ADJ= ";A
 1740 PRINT AT 4,2;"INPUT HYP"
 1750 INPUT H
 1760 PRINT AT 4,15;"HYP= ";H
 1770 LET C=A/H
 1780 LET X=ACS C*180/PI
 1790 PRINT AT 6,5;"ANGLE= ";X;" DEGS"
 1800 PRINT AT 10,3;"PRESS NEWLINE TO CONTINUE"
 1810 INPUT A$
 1820 GOTO 10
 1900 CLS 
 1910 PRINT AT 2,2;"INPUT COS"
 1920 INPUT C
 1930 PRINT AT 2,15;"COS= ";C;" DEGS"
 1940 PRINT AT 4,2;"INPUT HYP"
 1950 INPUT H
 1960 PRINT AT 4,15;"HYP= ";H
 1970 LET A=(COS (C*PI/180))*H
 1980 PRINT AT 6,5;"ADJ= ";A
 1990 PRINT AT 10,3;"PRESS NEWLINE TO CONTINUE"
 2000 INPUT A$
 2010 GOTO 10
 2100 CLS 
 2110 PRINT AT 2,2;"INPUT ADJ"
 2120 INPUT A
 2130 PRINT AT 2,15;"ADJ= ";A
 2140 PRINT AT 4,2;"INPUT COS"
 2150 INPUT C
 2160 PRINT AT 4,15;"COS= ";C;" DEGS"
 2170 LET H=A/(COS (C*PI/180))
 2180 PRINT AT 6,5;"HYP= ";H
 2190 PRINT AT 10,3;"PRESS NEWLINE TO CONTINUE"
 2200 INPUT A$
 2210 GOTO 10
 2300 CLS 
 2310 PRINT AT 2,2;"INPUT OPP"
 2320 INPUT O
 2330 PRINT AT 2,15;"OPP= ";O
 2340 PRINT AT 4,2;"INPUT ADJ"
 2350 INPUT A
 2360 PRINT AT 4,15;"ADJ= ";A
 2370 LET T=O/A
 2380 LET X=ATN T*180/PI
 2390 PRINT AT 6,5;"ANGLE= ";X;" DEGS"
 2400 PRINT AT 10,3;"PRESS NEWLINE TO CONTINUE"
 2410 INPUT A$
 2420 GOTO 10
 2500 CLS 
 2510 PRINT AT 2,2;"INPUT TAN"
 2520 INPUT T
 2530 PRINT AT 2,15;"TAN= ";T;" DEGS"
 2540 PRINT AT 4,2;"INPUT ADJ"
 2550 INPUT A
 2560 PRINT AT 4,15;"ADJ= ";A
 2570 LET O=(TAN (T*PI/180))*A
 2580 PRINT AT 6,5;"OPP= ";O
 2590 PRINT AT 10,3;"PRESS NEWLINE TO CONTINUE"
 2600 INPUT A$
 2610 GOTO 10
 2700 CLS 
 2710 PRINT AT 2,2;"INPUT OPP"
 2720 INPUT O
 2730 PRINT AT 2,15;"OPP= ";O
 2740 PRINT AT 4,2;"INPUT TAN"
 2750 INPUT T
 2760 PRINT AT 4,15;"TAN= ";T;" DEGS"
 2770 LET A=O/(TAN (T*PI/180))
 2780 PRINT AT 6,5;"ADJ= ";A
 2790 PRINT AT 10,3;"PRESS NEWLINE TO CONTINUE"
 2800 INPUT A$
 2810 GOTO 10
 2820 CLEAR 
 2830 SAVE "1025%7"
 2840 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