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 value of a variable applies only to those 50 REM subsequent CONTIGUOUS operations which used the previous value of 60 REM the variable. ie not necessarily to ALL subsequent operations 70 REM Can be easily modified for changing 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 changes.(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 month(2-20) ? "monthflag:UNTIL monthflag>1:PROCsort 365 REM Line 360. It is INTENDED that the original input data at month=1 should not be changed. Demo calcs will be wrong if you try altering 'monthflag>1' condition 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;TAB(24)"`";Total 430 ENDPROC 440 : 450 DEF PROCsort 460 LOCALi,j 470 FORi=2TOch STEP2 480 IF data(i)=monthflag data(i+1)=newrate:i=ch:ENDPROC:REM This line is needed to prevent a second array data( ) entry being created with the SAME month value as an existing entry 490 IF data(i)>monthflag THEN FOR j=(ch-1)TOi STEP-1:data(j+2)=data(j):NEXT:data(i)=monthflag:data(i+1)=newrate:i=ch:ENDPROC:REM This line puts an out of sequence change in its correct chronological position in array data( ) 500 data(ch)=monthflag:data(ch+1)=newrate 510 NEXT 520 ENDPROC 530 : 540 DEF PROCtitle 550 PRINTTAB(48,10)"ALTRIT Algorithm Demo." 560 PRINTTAB(48,11)"refer to listing: fkey8" 570 PRINTTAB(64,12)"& fkey9 to RUN" 580 PRINTTAB(48,13)"Calculations are only for demo" 590 PRINTTAB(48,14)"of the algorithm and to show" 600 PRINTTAB(48,15)"that the program functions 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, then 10 & 18." 640 PRINTTAB(48,20)"Now 9 & 4 for a back-dated" 650 PRINTTAB(48,21)"change to the early 10%'s but" 660 PRINTTAB(48,22)"but not those at month 18 on." 670 ENDPROC 680 : 690 DEF PROCwhy 700 LOCAL g 710 VDU7:PRINTTAB(50,24)"Wrong key";:REM g=INKEY(100):PRINTTAB(50,24)" " 740 ENDPROC