10 REM Altrit :demo
20 REM Remembers successive keyboard
inputs and organises the data into
30 REM chronological order according
to the program sequencing parameter.
40 REM A change of the numerical valu
e of a variable applies only to those
50 REM subsequent CONTIGUOUS operatio
ns which used the previous value of
60 REM the variable. ie not necessari
ly to ALL subsequent operations
70 REM Can be easily modified for cha
nging several variables
80 REM (C) DP-J 19May93
90 :
100 MODE3
110 *K.8CLS|MV.14|ML.|M
120 *K.9V.15|MRUN|M
130 :
140 DIM data(50): REM allows 25 change
s.(variables: month & interest rate)
150 FORi=0TO20:data(i)=0:NEXT
160 PROCtitle
170 INPUTTAB(0,0)"interest rate% "data
(1)
180 n=data(1):data(0)=1:ch=0:Total=0
190 PRINT"data( )= ";:FORi=0TO21:PRINT
;data(i)" ";:NEXT:PRINT"< array contents
" :REM demo only to display the first 10
changes
200 PROCaltrit:PROCtitle:PROCchange
210 GOTO180
220 END
230 :
240 DEF PROCaltrit
250 month=0
260 REPEAT
270 month=month+1
280 IF month=data(ch) n=data(ch+1):ch=
ch+2
290 PROCdemo
300 UNTIL month=20
310 ENDPROC
320 :
330 DEF PROCchange
340 REPEAT:PRINTTAB(0,24)"Do you want
to change interest rate (YyNn)?";
350 g$=CHR$(GET AND 95):IF INSTR("YyNn
",g$)=0:PROCwhy:UNTIL INSTR("YyNn",g$)<>
0
360 REPEAT:IFg$="Y" INPUT" Input new
rate % "newrate:INPUT" From what mont
h(2-20) ? "monthflag:UNTIL monthflag>1:P
ROCsort
365 REM Line 360. It is INTENDED that
the original input data at month=1 shoul
d not be changed. Demo calcs will be wro
ng if you try altering 'monthflag>1' con
dition without regard to line 280.
370 IF g$="N" PRINT
380 ENDPROC
390 :
400 DEF PROCdemo
410 Total=Total+n
420 PRINT;month;TAB(5)n"% x £100=";n;T
AB(24)"£";Total
430 ENDPROC
440 :
450 DEF PROCsort
460 LOCALi,j
470 FORi=2TOch STEP2
480 IF data(i)=monthflag data(i+1)=new
rate:i=ch:ENDPROC:REM This line is neede
d to prevent a second array data( ) entr
y being created with the SAME month valu
e as an existing entry
490 IF data(i)>monthflag THEN FOR j=(c
h-1)TOi STEP-1:data(j+2)=data(j):NEXT:da
ta(i)=monthflag:data(i+1)=newrate:i=ch:E
NDPROC:REM This line puts an out of sequ
ence change in its correct chronological
position in array data( )
500 data(ch)=monthflag:data(ch+1)=newr
ate
510 NEXT
520 ENDPROC
530 :
540 DEF PROCtitle
550 PRINTTAB(48,10)"ALTRIT Algorithm D
emo."
560 PRINTTAB(48,11)"refer to listing:
fkey8"
570 PRINTTAB(64,12)"& fkey9 to RUN"
580 PRINTTAB(48,13)"Calculations are o
nly for demo"
590 PRINTTAB(48,14)"of the algorithm a
nd to show"
600 PRINTTAB(48,15)"that the program f
unctions as"
610 PRINTTAB(48,16)"intended"
620 PRINTTAB(48,18)"INPUT:eg 10, then
7(%) & 8(mth),"
630 PRINTTAB(48,19)"then 8.5 & 13, the
n 10 & 18."
640 PRINTTAB(48,20)"Now 9 & 4 for a ba
ck-dated"
650 PRINTTAB(48,21)"change to the earl
y 10%'s but"
660 PRINTTAB(48,22)"but not those at m
onth 18 on."
670 ENDPROC
680 :
690 DEF PROCwhy
700 LOCAL g
710 VDU7:PRINTTAB(50,24)"Wrong key";:R
EM g=INKEY(100):PRINTTAB(50,24)"
"
740 ENDPROC