Commodore PET User Manual page 209

Table of Contents

Advertisement

Step 5: Print the answer string. To complete this addition routine, the
input and length test commands are inserted at the beginning of the fOR . ..
NEXT loop (statements 10 to 1010) and a PRINT and CLEAR string command
is added to the end (statements 1110 to 1130). The final program now reads
as follows:
Addition loop
Print C$
Clear C$
Clear screen
Input numeric strings
} Right justify strings
10 PR l NT" ;:')IeiUiAIID l Tl TONltii4EliE" : PF: l NT
20 INPUT A$ .. E$
:30 ELANK$="
40 X=LEN(A$):Y=LEN(E$)
50 IF X<Y THEN A$=LEFT$(ELANK$,Y-X)+A$
60 IF Y<X THEN E$=LEFT$(ELANK$,X-Y)+B$
1001::1 N=l
1010 D="::1
1020 FOR I=LEN(A$) TO 1 STEP-l
1030 A=VAL(MID$(A$,I,l»
1€140 A=A+D: D=€1
1050 E=VAL(MID$(B$, 1,1»
1€160 C=A+B
1070 IF (:>=10 THEN D=l
1080 IF D=l AND 1=1 THEN N=2
1090 C$=RIGHT$(STR$(C),N)+C$
1100 NEXT l
1110 PR l NT : PR l NT"
ANS~oJER=
".: C$
112€1 (:$="":
PRI~H:
GOTO 20
1130 END
Two sample runs of the program should give the following output:
?12::::45
??579
ANS~oJEF:=
12924
?1234567890123456
'-;:'?5794::::572
ANS~oJEF~=
123456794E:€167028
This addition routine overcomes the 9-digit numeric length limit. With a few
alterations and additions. this routine can also be adapted to print out and round
off to dollars and cents.
196

Hide quick links:

Advertisement

Table of Contents
loading

This manual is also suitable for:

Cbm

Table of Contents