This program collects monthly sales figures for 12 months, storing three-character month abbreviations in a string array and numeric values in a numeric array, then renders a horizontal bar chart on screen. Each bar is drawn using CHR$ 128 (a block graphic separator) followed by repeated CHR$ 134 characters (a solid block graphic) scaled so the highest value fills 22 columns. After the chart, total and average sales figures are printed. The SCROLL calls during input keep the display tidy on the 32-column screen, and the fractional STEP (B/22) in the FOR loop controls bar length proportionally to the peak value.
Program Analysis
Program Structure
The program is divided into two clear phases. Lines 9000–9160 handle data entry: two parallel arrays (A$(12,3) for month names and A(12) for sales values) are populated via INPUT, with the peak value tracked in B. Lines 9170–9270 render the bar chart and summary. Line 9997 stops execution; line 9998 saves the program; line 9999 loops back to redraw — allowing the chart to be redrawn without re-entering data.
Array Design
DIM A$(12,3) declares a 12-element string array where each element is exactly 3 characters, enforcing the “first 3 characters” prompt. DIM A(12) holds the corresponding numeric sales figures. The parallel-array approach is idiomatic for this dialect, which lacks record or struct types.
Bar Chart Rendering
Each bar is drawn on a single PRINT line. The month name and value are printed left-aligned, then TAB 9 positions the cursor before the bar. CHR$ 128 (block graphic ▝ or similar solid block, used as a visual separator) precedes the bar body. The bar itself consists of repeated CHR$ 134 characters printed by the inner FOR C loop.
Scaling Technique
Bar length is controlled by iterating FOR C=.01 TO A(N) STEP B/22. Dividing the peak value B by 22 sets the step size so the largest bar prints exactly 22 block characters, while all others are proportionally shorter. Starting at .01 rather than 0 or 1 means the loop always executes at least once for any positive sales value, ensuring every month gets at least one character.
Display Management
Four SCROLL calls (lines 9050, 9090, 9130, 9140) during data entry scroll the display upward before and after each prompt/response pair, keeping the screen uncluttered during the 12-iteration input loop. CLS at line 9170 clears the screen before chart rendering.
Summary Output
Lines 9260–9270 print total and average sales below the chart. The comma separators in PRINT ,,,,"TOTAL SALES = $";T advance the print position by four tab columns, indenting the summary to approximate centre-screen alignment on a 32-column display.
Notable Anomalies
LET T=0appears at both line9020and line9175. The accumulator is reset a second time just before the chart loop, which is redundant but harmless; it may reflect an edit where the chart loop was intended to be re-enterable from9999without re-accumulating.- If any sales value is zero,
Bremains zero after all entries andSTEP B/22becomesSTEP 0, which would cause an infinite loop. The program assumes at least one non-zero entry. Bis initialised to0but never reset before the chart phase; ifGOTO 9999is reached after a prior run with different data,Bcorrectly retains the peak from the most recent input session.
Line Reference Summary
| Lines | Purpose |
|---|---|
9000–9030 | Array and variable initialisation |
9040–9160 | 12-month data entry loop, peak tracking |
9170–9175 | Screen clear, accumulator reset |
9180–9250 | Bar chart rendering loop |
9260–9270 | Total and average summary |
9997 | STOP |
9998 | SAVE program |
9999 | Redraw loop entry point |
Content
Source Code
9000 DIM A$(12,3)
9010 DIM A(12)
9020 LET T=0
9030 LET B=0
9040 FOR N=1 TO 12
9050 SCROLL
9060 PRINT "MONTH (1ST 3 CHAR)? ";
9070 INPUT A$(N)
9080 PRINT A$(N)
9090 SCROLL
9100 PRINT "SALES? ";
9110 INPUT A(N)
9120 PRINT A(N)
9130 SCROLL
9140 SCROLL
9150 IF A(N)>B THEN LET B=A(N)
9160 NEXT N
9170 CLS
9175 LET T=0
9180 FOR N=1 TO 12
9190 PRINT A$(N);" ";A(N);TAB 9;CHR$ 128;
9200 LET T=T+A(N)
9210 FOR C=.01 TO A(N) STEP B/22
9220 PRINT CHR$ 134;
9230 NEXT C
9240 PRINT
9250 NEXT N
9260 PRINT ,,,,"TOTAL SALES = $";T
9270 PRINT ,,"AVERAGE MONTH = $";T/12
9997 STOP
9998 SAVE "GRAFI%T"
9999 GOTO 9170
Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.
