Shoppers Friend is a unit-price comparison program that helps users decide which of two branded products offers better value for money. The user enters a name, quantity, and price for each of two brands; the program then divides price by quantity to compute a per-unit cost and declares the cheaper brand the best buy. Three outcomes are handled: Brand 1 cheaper, Brand 2 cheaper, or equal value. Lines 700–720 implement a “press any key to continue” loop that would restart the comparison, though this code is never reached due to the STOP at line 530.
Program Analysis
Program Structure
The program is divided into clearly separated functional blocks, using line-number ranges as logical sections:
- Lines 10–50: Title display and decorative asterisk banner (15 asterisks via a
FORloop). - Lines 100–180: Input for the first brand — name (
X$), quantity (M), and price (N). - Lines 200–280: Input for the second brand — name (
Y$), quantity (Q), and price (R). - Lines 300–330: Comparison logic and routing via
IF…GOTO. - Lines 400–530: Result display and program halt.
- Lines 600–610: Equal-value handler, falls through to the unit-price display.
- Lines 700–720: Dead code — a keypress-wait loop intended to restart the program.
- Lines 800–900: Utility lines for saving and auto-running.
Comparison Logic
The core decision is made at lines 300–320 by computing the unit price as N/M (price divided by quantity) for Brand 1 and R/Q for Brand 2:
| Line | Condition | Action |
|---|---|---|
| 300 | N/M = R/Q | Jump to line 600 (equal value message) |
| 310 | N/M < R/Q | Jump to line 400 (Brand 1 is best buy) |
| 320 | (implicit else) | Brand 2 is best buy, fall through to line 500 |
Lines 500–510 always print both unit prices regardless of which brand won, providing a useful cost breakdown before the program halts at line 530.
Bugs and Anomalies
- Typo at line 320: The message reads
"IS BCST BUY"instead of"IS BEST BUY"— a transcription error that only affects Brand 2’s winning message. - Dead code at lines 700–720: The “press any key” loop and
GOTO 10restart are unreachable because execution always hitsSTOPat line 530 or falls through to it via line 610. No path in the program leads to line 700. - Division by zero risk: If the user enters
0for either quantity (MorQ), the divisionN/MorR/Qwill produce an error with no guard. - Missing dollar sign for Brand 2 price prompt: Line 160 prompts
"PRICE: $"for Brand 1, but line 260 prompts only"PRICE: "without the dollar symbol — an inconsistency in the UI. - Currency symbol in unit display: Line 500 prints
"UNIT = $"but line 510 omits the dollar sign, again inconsistent.
Key BASIC Idioms
- The asterisk banner at lines 20–40 uses a
FOR…NEXTloop withPRINT "*";(semicolon suppresses newline) — a common ZX81 technique for drawing horizontal rules without a dedicated graphics command. - Input values are echoed back to the screen immediately after entry (e.g. lines 120, 150, 180), which was necessary on the ZX81 since
INPUTconsumed the display area during entry. - The
REMat line 5 stores the program title in inverse video characters, serving as an in-memory label visible in the program listing.
Notable Structural Choice
The equal-value branch at line 600 prints an equivalence message and then uses GOTO 500 to fall into the same unit-price display used by the other branches. This avoids duplicating the display code and is a reasonable subroutine-like pattern without using GOSUB.
Content
Source Code
5 REM %S%H%O%P%P%E%R%S% %F%R%I%E%N%D
10 PRINT "SHOPPERS FRIEND"
20 FOR L=1 TO 15
30 PRINT "*";
40 NEXT L
50 PRINT
100 PRINT "FIRST BRAND NAME:"
110 INPUT X$
120 PRINT X$
130 PRINT "QUANTITY: ";
140 INPUT M
150 PRINT M
160 PRINT "PRICE: $";
170 INPUT N
180 PRINT N
200 PRINT "SECOND BRAND NAME:"
210 INPUT Y$
220 PRINT Y$
230 PRINT "QUANTITY: ";
240 INPUT Q
250 PRINT Q
260 PRINT "PRICE: ";
270 INPUT R
280 PRINT R
300 IF N/M=R/Q THEN GOTO 600
310 IF N/M<R/Q THEN GOTO 400
320 PRINT Y$;" IS BCST BUY"
330 GOTO 500
400 PRINT X$;" IS BEST BUY"
500 PRINT X$;" UNIT = $";N/M
510 PRINT Y$;" UNIT = $";R/Q
520 PRINT
530 STOP
600 PRINT X$;" = ";Y$
610 GOTO 500
700 PRINT "FOR MORE,PRESS ANY KEY"
710 IF INKEY$="" THEN GOTO 700
720 GOTO 10
800 SAVE "1003%5"
900 RUN
Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.
