--- title: "Unit Price" id: 56988 type: "computer_media" slug: "unit-price" url: "http://localhost/computer_media/unit-price/" markdown_url: "http://localhost/computer_media/unit-price.md" published_at: "2024-10-02T01:18:44+00:00" modified_at: "2026-03-30T21:20:27+00:00" author: "David Anderson" featured_image: url: "http://localhost/wp-content/uploads/2024/10/13_UntPri.png" excerpt: "A handy retail utility that takes item name, quantity, and total price, then instantly calculates and displays the cost per unit." 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: "Finance" slug: "finance" taxonomy: "genre" url: "http://localhost/type/finance/" media_contents: - id: 56732 title: "Timex Sinclair Public Domain Library Tape 1001" type: "computer_media" url: "http://localhost/computer_media/timex-sinclair-public-domain-library-tape-1001/" media_type: "Program" download_url: "https://archive.org/download/timex-sinclair-software-archive/Timex%20Sinclair%20Public%20Domain%20Library%20Tape%201001%20%28198x%29%28Timex%20Sinclair%20Public%20Domain%20Library%29%28TS1000%29%28US%29%28Cassette%29.zip/Timex%20Sinclair%20Public%20Domain%20Library%20Tape%201001%20%28198x%29%28Timex%20Sinclair%20Public%20Domain%20Library%29%28TS1000%29%28US%29%28Cassette%29%2FSide%20B%2F13_UntPri.tzx" mediadate: "198x" images: - url: "http://localhost/wp-content/uploads/2024/10/13_UntPri.png" media_type_tags: "Finance, Software" --- # Unit Price This program calculates the unit price of an item by dividing the total price paid by the quantity purchased. The user enters an item name (as a string), a quantity, and a total price, and the program displays the computed unit price formatted as a dollar amount. After displaying results, it waits for a keypress using a busy-loop on INKEY$ before clearing the screen and looping back to accept another item. Lines 275–400 are unreachable during normal execution, serving as a save/run block appended below the program’s logical end at line 250. *** ## Program Analysis ### Program Structure The program is organized as a straightforward input-process-output loop. Execution begins at line 10 and cycles continuously through data entry, calculation, display, and a keypress wait before clearing the screen and repeating. The logical program ends at line 250 (`GOTO 10`), making lines 275–400 permanently unreachable during normal execution. 1. **Lines 10–105:** Initialize `U`, prompt for and echo item name (`N$`), quantity (`Q`), and price (`P`). 2. **Line 110:** Core calculation — `U = P / Q`. 3. **Lines 120–250:** Display result, prompt user, wait for keypress, clear screen, loop. 4. **Lines 275–400:** Unreachable tail block containing `CLEAR`, `SAVE`, and `RUN`. ### Key BASIC Idioms The keypress wait at line 230 uses the standard busy-loop idiom `IF INKEY$="" THEN GOTO 230`, which spins until any key is pressed. This is the conventional non-blocking wait technique in the absence of a `PAUSE` statement with key detection. Each `INPUT` statement is immediately followed by a `PRINT` of the entered value (lines 70, 100, 40). This echoes input back to the screen since the system’s own input prompt line is overwritten or scrolled away after entry, giving the user a confirmation of what was typed. ### Variables | Variable | Purpose | | --- | --- | | `U` | Computed unit price (total ÷ quantity) | | `N$` | Item name entered by user | | `Q` | Quantity of items | | `P` | Total price paid | ### Notable Techniques and Anomalies - **Initialization of `U`:** Line 10 sets `U=0` explicitly, though this is redundant since `U` is always assigned at line 110 before it is used. This may reflect cautious coding style. - **No division-by-zero guard:** If the user enters `Q=0`, the division at line 110 will produce an error. There is no input validation to prevent this. - **No currency formatting:** The unit price `U` is printed as a raw floating-point number. Values will display with the system’s default numeric formatting, which may show more decimal places than is typical for currency display. - **Blank PRINT statements:** Lines 45, 75, 105, 200, and 210 are bare `PRINT` statements used solely for vertical spacing, a common formatting technique. - **Unreachable lines 275–400:** The `CLEAR`, `SAVE`, and `RUN` commands beyond line 250 are never reached during execution; they exist as a program-save and auto-restart footer outside the runtime loop. ## Source Code ``` 5 REM **UNIT PRICE** 10 LET U=0 20 PRINT "ITEM NAME IS "; 30 INPUT N$ 40 PRINT N$ 45 PRINT 50 PRINT "QUANTITY OF ITEMS = "; 60 INPUT Q 70 PRINT Q 75 PRINT 80 PRINT "TOTAL PRICE PAID FOR ITEMS = $ "; 90 INPUT P 100 PRINT P 105 PRINT 110 LET U=P/Q 120 PRINT N$;" UNIT PRICE = $ ";U 200 PRINT 210 PRINT 220 PRINT "FOR MORE,PRESS ANY KEY" 230 IF INKEY$="" THEN GOTO 230 240 CLS 250 GOTO 10 275 CLEAR 300 SAVE "1001%3" 400 RUN ```