--- title: "Average" id: 57104 type: "computer_media" slug: "average" url: "http://localhost/computer_media/average/" markdown_url: "http://localhost/computer_media/average.md" published_at: "2024-10-03T23:30:51+00:00" modified_at: "2026-03-30T21:20:00+00:00" author: "David Anderson" featured_image: url: "http://localhost/wp-content/uploads/2024/10/53_Aver.png" excerpt: "A compact averages calculator that accepts any list of numbers, stops on zero, and instantly displays the arithmetic mean before resetting for the next calculation." category: - name: "Archived Media" slug: "archived-media" taxonomy: "category" url: "http://localhost/category/archived-media/" post_tag: - name: "Downloadable" slug: "downloadable" taxonomy: "post_tag" url: "http://localhost/tag/downloadable/" - name: "TS 1000" slug: "ts1000" taxonomy: "post_tag" url: "http://localhost/tag/ts1000/" model: - name: "Timex/Sinclair 1000" slug: "ts-1000" taxonomy: "model" url: "http://localhost/model/ts-1000/" genre: - name: "Mathematics" slug: "mathematics" taxonomy: "genre" url: "http://localhost/type/mathematics/" media_contents: - id: 56733 title: "Timex Sinclair Public Domain Library Tape 1002" type: "computer_media" url: "http://localhost/computer_media/timex-sinclair-public-domain-library-tape-1002/" media_type: "Program" mediadate: "198x" images: - url: "http://localhost/wp-content/uploads/2024/10/53_Aver.png" media_type_tags: "Mathematics" --- # Average This program computes the arithmetic mean of a series of numbers entered by the user. It accumulates a count in variable N and a running total in T, then divides T by N when the user enters 0 as a sentinel value to terminate input. After displaying the result, it loops back to line 10 to reset the counters and run again, allowing repeated calculations without restarting. The REM statement at line 5 and the title PRINT at line 22 both use inverse-video characters to display “AVERAGES” as a highlighted heading. *** ## Program Analysis ### Program Structure The program is organized as a simple sequential loop with a sentinel-terminated input phase followed by a results display phase. Control flow is entirely managed by `GOTO` statements rather than subroutines. 1. **Initialization (lines 10–20):** Variables `N` (count), `T` (total), and `A` (average) are all set to zero. 2. **Title display (lines 22–23):** The heading “AVERAGES” is printed in inverse video, followed by a blank line. 3. **Input loop (lines 25–60):** The user is prompted repeatedly; each non-zero value increments `N` and adds to `T`, then loops back to line 25. 4. **Calculation and display (lines 70–100):** On sentinel input of 0, `A` is computed as `T/N`, the screen is cleared, and the average is printed. 5. **Outer reset loop (line 110):**`GOTO 10` resets all variables and repeats the entire process indefinitely. ### Variables | Variable | Purpose | | --- | --- | | `N` | Count of numbers entered | | `T` | Running total of entered values | | `A` | Computed arithmetic mean (T/N) | | `Z` | Most recently entered number / sentinel | ### Key BASIC Idioms - **Sentinel value:** Entering `0` terminates the input loop — a classic idiom for indefinite input without a predetermined count. - **Re-initialization via GOTO:** Rather than using a separate GOSUB or structuring the reset explicitly, `GOTO 10` at line 110 re-executes the `LET` assignments to reset state, which is concise but relies on the program re-running those lines each cycle. - **Inline echo:** Line 40 prints `Z` immediately after input, giving the user a confirmation of what was recorded. ### Notable Techniques The inverse-video “AVERAGES” title is used in both the `REM` at line 5 (visible in the listing) and the `PRINT` at line 22 (visible at runtime), providing a consistent styled heading. The `REM` usage here is purely cosmetic for the program listing. ### Bugs and Anomalies - **Division by zero:** If the user immediately enters `0` without providing any numbers, line 70 will attempt to evaluate `T/N` with `N=0`, causing a division-by-zero error. There is no guard against this case. - **Negative sentinel ambiguity:** The sentinel is hard-coded as `0`, meaning zero cannot itself be included as a data value in the series, which is a known limitation of sentinel-based designs. - **Redundant variable A:** Variable `A` is initialized at line 20 but is only ever assigned at line 70 immediately before use; the initialization is unnecessary. - **Lines 120–130:** The `SAVE` and `RUN` at lines 120–130 are unreachable during normal execution since the program loops indefinitely via line 110. ## Source Code ``` 5 REM %A%V%E%R%A%G%E%S 10 LET N=0 15 LET T=0 20 LET A=0 22 PRINT "%A%V%E%R%A%G%E%S" 23 PRINT 25 PRINT "ENTER A NUMBER(ENTER 0 TO STOP)" 30 INPUT Z 35 IF Z=0 THEN GOTO 70 40 PRINT Z 45 LET N=N+1 50 LET T=T+Z 60 GOTO 25 70 LET A=T/N 80 CLS 90 PRINT "THE AVG. NR. IS ";A 100 PRINT 110 GOTO 10 120 SAVE "1005%3" 130 RUN ```