The Round-Up: An Update Programming Tutorial

Author(s): Bill Jones
Publication: Update Magazine
Pub Details: Update October 1988
Date: October 1988
Pages: 11-12

This is a program designed for UPDATE to demonstrate several abilities of dealing with numbers. FIRST, the “INT” function “ROUNDS DOWN” figures. All businesses do the opposite, ROUNDING UP to the nearest cent. This can make a busy department store quite a few dollars during a day’s opeation.

Next, PRINT USING is a ROM routine used with some computers to “Format a Column of Figures”. Mr. Sinclair left PRINT USING out of his Sinclair Basic ROM. But anything that a ROM routine can do can also be done by programming in RAM. Here we use a little routine that simulates a PRINT USING function to print the dollar sign, then print a column of figures with decimal points aligned. Also, Zeroes are added when necessary.

The use of INT (INTEGER) in math calculations to assign the resultant to a variable causes errors. The error is only in the assignment to the variable. The “Floating Point Calculation” has the right value “in there somewhere”, but a small fraction is lost when INT is used in a calculation. EXAMPLE: try this group of direct commands: <LET a= 1.0954><LET b=INT a> <LET c=INT (100000*(a-b)) > <PRINT c>. Floating point calc drops a tiny fraction that can be troublesome. LINE number 9710 uses a little “floating point k factor” of .0001 and then adds .005 for “rounding up” to the nearest cent.

Line 9712 adds a whole number if a round-up changes 99 cents to $1.00. Then the integer number and the decimal fraction are assigned to a$ and b$ for printing. This is because the TS-2068 prints decimal numbers as “0.4”, “0.25”, which is not convenient to print directly. The “STR$” function transfers a numeric value into a literal value to place in a string. Try this EXAMPLE: <LET a=12> <LET a$=STR$ a><PRINT a$>. Amazing, eh? Now lets go the opposite way: <LET a$=”386″><LET a=VAL a$><PRINT a>. Stupendous!! Mess around this way with STR$ and VAL, and you’ll get good at using numbers in both simple variables and in string variables.

Next, line 9718 does a bit of “String Slicing”. Some of the odd presentations of fractions may result in B$ being “.020”. To just present “cents”, we chop off the last “0”. Lets try that separately now: <LET b$=”.020><PRINT b$( TO 3) >. Or: <LET b$=b$( TO 3) ><PRINT b$>. Try several other examples like: <LET b$=”I LOVE THIS”><PRINT b$><LET b$=b$( TO 6) ><PRINT B$>.

Next, line 9720 “sums” the figures, but only IF x=1. In the beginning we LET x=0. So, each input figure is summed as they are typed in. When we want to present the sum, we type “s” instead of a number. Back at line 9700, the input of “s” instead of a number gives us an error (unless variable s has been assigned a number). The error trips the first ON ERR GO TO 9800. Then at line 9800, the ERR is RESET, a line is drawn, and a dollar mark is printed. Then the GO TO 9710 processes the SUM to be printed.

Finally, line 9770 prints the figures, with all decimals aligned at your TAB setting. A$ carries the WHOLE dollar value and B$ carries the CENT value. Then line 9780 stops if the SUM has printed (x=1), or line 9790 returns to pick up the next input number. ONE MORE line needs to be discussed. LINE 9700 has a second <ON ERR GO TO 9706>, which is the next line in the program. “STOP” creates the error so that the ON ERR programming is cancelled (no open ON ERR to mess you up later).

Now thats a lot of programming functions in a few short BASIC lines, and likely less memory is used than if Sinclair had put the routines in ROM and given us a PRINT USING syntax to use. And, because it is in BASIC programming in RAM, we can alter it as needed to tailor the routine to our needs. There are many ways you can modify this utility to use as a SUB-ROUTINE in your programs. Change PRINT to LPRINT in line 9790 to put it on paper. But if you just want a “Column Adder”, use it the way it is.

9680>REM [ THE ROUND-UP         ]
[ Summing of Columns ]
[ PSEUDO PRINT USING ]
9690 CLS : LET x=0: LET t=0: LET
tb=25:
REM [ variables are "t=Total.
tb=tab. x=switch that
turns on by ERROR for
totalling. ]
9691
9692 REM [ Lines through 9700
may be eliminated.
Then the input to
the routine would
be numbers assigned
to varable a.
9694 REM [ The Routine end is
line 9780. Change
line 9780 to RETURN
for Sub-routine use.
9697 REM
9700 ON ERR GO TO 9800: INPUT "K
ey in Number- or ""s"" for SUM
";a: ON ERR GO TO 9706: STOP
9706 ON ERR RESET : IF t=0 THEN
PRINT TAB tb-5;"$";
9710 LET b=INT a: LET c=INT (100
*(a-b+.0001+.005)): LET d=c/100
9712 IF c>99 THEN LET b=b+1: LET
c=0: LET b$=".00"
9714 IF c>=0 AND c<10 THEN LET b
$=".0"+STR$ c
9716 IF c>9 THEN LET b$="."+STR$
c+"0"
9718 LET a$=STR$ b: IF LEN b$>3
THEN LET b$=b$( TO 3)
9720 IF x=0 THEN LET t=t+b+(c/10
0)
9770 PRINT TAB tb-LEN a$;a$;b$
9780 IF x=1 THEN LET x=0: STOP
9790 GO TO 9700
9800 ON ERR RESET : PRINT TAB tb
-4;"_______"'TAB tb-6;"$";: LET
x=1: LET a=t: GO TO 9710

This is really a CLUB Issue of UPDATE

If the reader has concluded that UPDATE is plaggerizing and stealing articles for the various Club newsletters, then the objective is missed completely. The reason for the selected re-prints is to give samples of the excellent material that is produced in these excellent club publications. So, you get two benefits from these club articles. First, you get the good articles to digest. Second, you get a chance to savor the personality of the clubs and the quality to expect in club publications. Then, of course, you get the address to use to JOIN the club or Subscribe to their newsletter. Actually UPDATE has a bank of excellent NEW articles about the TS-2068 and the QL, enough to fill at least the next five issues. The Sinclair user groups need an influx of new members to spark new life and direction. Especially, the clubs need QL and TS-2068 members to join and form a special interest group within the existing Sinclair special interest Club. This is UPDATE”S way of helping to round up new members of the Sinclair User Clubs. Unfortunately, space does not permit the introduction of all clubs in one issue, but we’ll get rountuit in future issues.

Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.