[The following program and explanation was written for the T/S 1000/ZX81 with a 16k RAM pack.] This program computes interest over a certain period of time, at a selected interest rate. But what makes this program special is it’s extensive input error checking at lines 90-120, 210-240, and 280-310. Using a string variable, the code of the input can be checked within specific parameters. The next line converts the value of the string to a numerical value. Where it is then checked to see if it is greater than zero.
The sub-routine at lines 1000-1210 puts a dollar sign, commas, and decimal point in the proper places. Then it is centered. This routine was found in the “Timex/Sinclair 1000 Basic Handbook“, by Douglas Hergert, published by Sybex.
At line 140, the amount is rounded to two decimal places should the input contain three numbers after the decimal point. At this point, the program GOSUBs to 1000. Line 1020 assigns the string version of T, supplied by the STR$ function to the variable T$. S$ provides the form that the number should take, and accomplishes this using the “string slicing” technique. Lines 1030-1060 search for a decimal point. Line 1070 causes the program to branch if there are no cents. Lines 1080-1100 store the cents in S$, as lines 1160-1170 store the dollars. Lines 1180-1200 leave the commas in S$. After all this manipulation, we jump back to the main program and use the print-centering routine in lines 460-470.
After printing the dollar amount, you get a choice: (1) do it again, or (2) stop (using a user-friendly INKEY$ routine found at lines 550-650. To create the percent sign in line 340, use: SHIFTED GRAPHICS 2; SLASH; SHIFTED GRAPHICS 4. Lines 370 and 380 actually compute the interest. The rest of the program is to make it “friendly”.
VARIABLES:
A$/T & A-ORIGINAL AMOUNT Y$/N -YEARS I$/J & I-INTEREST S$/ -PRINT FORMAT P$/ -FORMATTED TOTAL T / -TOTAL ACCRUED K$/ -INKEY$ SP/ -FORMAT LENGTH T$/ -VALUE OF T P / -DECIMAL POSITIONING Z / -LOOP N$/ -DOLLARS TEST
00001 REM "INTEREST"
0005 REM BY JEFF AND STEPHEN BROTHERS
0010 SLOW
0020 SCROLL
0030 PRINT AT 21,7;"INTEREST ACCRUED"
0040 SCROLL
0050 PRINT
0060 SCROLL
0070 PRINT "ORIGINAL AMOUNT: "
0080 SCROLL
0090 INPUT A$
0100 IF CODE A$ <= 26 OR CODE A$ >= 38 THEN GOTO 90
0110 LET A= VAL A$
0120 IF A <= 0 THEN GOTO 90
0130 LET T=A
0140 LET T= INT (A*100+.5)/100
0150 GOSUB 1000
0160 LET P$=S$(SP TO LEN S$)
0170 PRINT AT 20,17;"$";P$
0180 SCROLL
0190 PRINT "NUMBER OF YEARS:"
0200 SCROLL
0210 INPUT Z$
0220 IF CODE Z$ <= 26 OR CODE Z$ >= 38 THEN GOTO 210
0230 LET N= VAL Z$
0240 IF N <= 0 THEN GOTO 210
0250 PRINT AT 20,17;N
0260 SCROLL
0270 PRINT "YEARLY INTEREST RATE:"
0280 INPUT J$
0290 IF CODE J$ <= 26 OR CODE J$ >= 38 THEN GOTO 280
0300 LET J= VAL J$
0310 IF J <= 0 OR J>100 THEN GOTO 280
0320 LET I=J/100
0330 SCROLL
0340 PRINT AT 20,22;J;" */*"
0350 SCROLL
0360 PRINT AT 21,31; AT 21,0;
0370 LET T=A*(1+I) ** N
0380 LET T= INT (T*100+.5)/100
0390 IF N <> 1 THEN PRINT "AFTER ";N;" YEARS, YOU WILL HAVE:"
0400 IF N=1 THEN PRINT "AFTER ";N;" YEAR, YOU WILL HAVE:"
0410 SCROLL
0420 PRINT
0430 GOSUB 1000
0440 SCROLL
0450 PRINT AT 21,31; AT 21,0;
0460 LET P$=S$(SP TO LEN S$)
0470 PRINT TAB (1+ LEN S$- LEN P$);"$";P$
0480 SCROLL
0490 PRINT AT 21,31; AT 21,0;
0500 PRINT
0510 FOR A=0 TO 9
0520 SCROLL
0530 PRINT AT 21,31; AT 21,0;
0540 NEXT A
0550 PRINT AT 16,7;"(1)-AGAIN"
0560 PRINT AT 17,7;"(2)-STOP"
0570 PRINT AT 19,5;"PRESS DESIRED FUNCTION"
0580 IF INKEY$ ="" THEN GOTO 580
0590 LET K$= INKEY$
0600 IF K$ <> "1" AND K$ <> "2" THEN GOTO 580
0610 IF K$="1" THEN GOTO 630
0620 STOP
0630 FOR A=0 TO 21
0640 SCROLL
0650 NEXT A
0660 RUN
1000 LET S$="000,000,000.00"
1010 LET SP=12
1020 LET T$= STR$ T
1030 LET P=0
1040 FOR Z=1 TO LEN T$
1050 IF T$(Z)="." THEN LET P=Z
1060 NEXT Z
1070 IF P=0 THEN GOTO 1150
1080 FOR Z=1 TO LEN T$-P
1090 IF Z <= 2 THEN LET S$(SP+Z)=T$(P+Z)
1100 NEXT Z
1110 LET N$=T$(1 TO P-1)
1120 IF N$ <> "" THEN GOTO 1160
1130 LET SP=SP-1
1140 GOTO 1210
1150 LET N$=T$
1160 FOR Z= LEN N$ TO 1 STEP -1
1170 LET SP=SP-1
1180 IF INT (SP/4)*4=SP THEN LET SP=SP-1
1190 LET S$(SP)=N$(Z)
1200 NEXT Z
1210 RETURN
9997 STOP
9998 SAVE "INTEREST"
9999 RUN
Note: Type-in program listings on this website use ZMAKEBAS notation for graphics characters.