--- title: "Grafit" id: 57569 type: "computer_media" slug: "grafit" url: "http://localhost/computer_media/grafit/" markdown_url: "http://localhost/computer_media/grafit.md" published_at: "2024-10-05T22:11:40+00:00" modified_at: "2026-04-03T07:58:22+00:00" author: "David Anderson" featured_image: url: "http://localhost/wp-content/uploads/2024/10/grafit.png" excerpt: "A 12-month sales bar chart that scales each row of block graphics to the highest value entered, then totals and averages your figures automatically." 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: "Business" slug: "business" taxonomy: "genre" url: "http://localhost/type/business/" media_contents: - id: 56721 title: "Synchro-Sette April 1983" type: "computer_media" url: "http://localhost/computer_media/synchro-sette-april-1983/" media_type: "Program" mediadate: "April 1983" images: - url: "http://localhost/wp-content/uploads/2024/10/grafit.png" media_type_tags: "Business" --- # Grafit 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=0` appears at both line `9020` and line `9175`. 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 from `9999` without re-accumulating. - If any sales value is zero, `B` remains zero after all entries and `STEP B/22` becomes `STEP 0`, which would cause an infinite loop. The program assumes at least one non-zero entry. - `B` is initialised to `0` but never reset before the chart phase; if `GOTO 9999` is reached after a prior run with different data, `B` correctly 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 | ## 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 ```