RUN
DO YOU PREFER BL OR LOTUS CARS? B
HOW MUCH ARE YOU WILLING TO SPEND ?6000
IN THAT CASE YOU CAN AFFORD THESE:
3198
MINI 1000
CITY
4 699
METRO HLE
5419
MAESTRO 1 .
3L
5660
MONTEGO 1 .
6
DO
YOU PREFER
BL OR LOTUS
CARS? L
HOW
MUCH ARE
YOU WILLING
TO SPEND ? 1 9 0 0
IN
THAT CASE,
YOU CAN AFFORD THESE:
Out of DATA at line 100
You will notice that line 50 usees the RESTORE statement to set the data
‘pointer’ to either line 170 where BL data is stored or to line 270 where Lotus
data is stored. This ensures that data is read from the correct list.
Lines 90 to 130 attempt to read off eight sets of data from the data lists, but fail
when Lotus data is selected as only three sets of data are provided. The message
Out of DATA at line 100
indicates the failure to find enough entries in the data table. Methods of
overcoming the problem are given in chapter 27 which deals with error handling.
110
23 Integer handling
Two special arithmetical functions are provided which produce integer (ie whole
number) results. These integer functions are DIV and MOD (Division and
MODulus).
The result of a normal division has two parts - the whole number part and the
remainder. Normally the remainder is quoted as a decimal fraction. Thus
11/4 = 2.75 or 2%
However the functions DIV and MOD enable the whole number part and the
remainder to be calculated separately. Thus
11 DIV 4=2
(ie 4 goes into 11 two times) and
11 MOD 4=3
(ie the remainder is 3).
A simple division test shows how they can be used.
5 CLS
10 PRINT "Division test!"
20 PRINT "Answer with a whole number, and a" '
" remainder "
30 REPEAT
40 X = RND (100)
50 Y = RND ( 10 )
60 PRINT ' "What is ";X;" divided by ";Y
70 INPUT A
80 INPUT "Remainder? "B
90 IF A=Y DIV Y AND B=X MOD Y THEN PRINT "That's
correct" ELSE PRINT "That's wrong"
100 PRINT 1 "Press any key to continue"
110 T=GET
120 UNTIL FALSE
DIV and MOD are used whenever you are trying to convert units - for example
seconds into minutes. Thus 500 seconds is 500 DIV 60 minutes and 500
MOD 6 0 seconds - that is 8 minutes 20 seconds.
For example this program prints a 24 hour clock
Ill
5 PRINT "Please input the time"
10 INPUT "Hours ",H
20 INPUT "Minutes ",M
30 TIME=H* 360000 + M* 6000
40 CLS
50 REPEAT
60 SEC= ( T IME DIV 100) MOD 60
70 MIN= ( T IME DIV 6000) MOD 60
80 HR= ( TIME DIV 360000) MOD 24
90 PRINT TAB ( 7 , 12) HR; " : " ; MIN ; " : " ; SEC ; SPC ( 2 )
100 UNTIL FALSE
The clock is improved if you type VDU 23,1,0;0;0;0; which switches off
the flashing cursor (see chapter 10). The next program would keep time to the
end of the century - if you left the computer switched on that long!
10 lastminute=0
20 MODE 7
30 PROCOFF
40 PROGgetdatetime
50 CLS
60 REPEAT
70 PROCshowtime
80 UNTIL FALSE
90 END
100
110 DEF PROCgetdatetime
120 CLS
130 PRINT"Please supply the day, month and year"
140 PRINT "as numbers e.g. 24 10 1984"
150 PRINT
160
170 REPEAT
180 PRINT TAB (5 , 10 ); "Day
190 INPUT TAB) 12, 10) ""day
200 UNTIL day>0 AND day<32
210
220 REPEAT
230 PRINT TAB (5 , 12 ); "Month " ;
240 INPUT TAB (12,12)"" month
250 UNTIL months- 0 AND month<13
260
270 REPEAT
280 PRINT TAB (5 , 14 ) ; " Year " ;
290 INPUT TAB (12, 14) ""
year
112
300 UNTIL year> 1 799 AND year<2500 OR year>0 AND
year < 9 9
310 IF year<99 THEN year=year+l 90 0
320
330 CLS
340 PRINT"and now the time please"
350 PRINT "using a 24 hour clock"
360
370 REPEAT
380 PRINT TAB (5 , 10 ); "Hours
390 INPUT hour
400 UNTIL hour>-l AND hour<24
410
420 REPEAT
430 PRINT TAB (5 . 12 ); "Minutes
440 INPUT minute
450 UNTIL minute>-l AND minute<60
460
470 T IME = 1 0 0 * 6 0 * (minut e + 6 0 * hour )
480 ENDPROC
490
500
510 DEF PROCshowtime
520 IF T IME> 8 6 4 0 0 0 0 THEN
T IME=T IME- 8640000
530 hour=T IME DIV 360000 MOD 24
540 minut e=T IME DIV (100*60) MOD 60
550 second=TIME DIV 100 MOD 60
560 IF (hour=0 AND minute=0 AND
lastminute=5 9 ) THEN PROCincdate
570 lastminute=minute
580 PRINT TAB (0 , 0) ; "Date = ";day; ”
590 RESTORE 600
600 DATA
Jan , Feb , Mar , Apr , May , June, July, Aug , Sept, Oct, Nov, Dec
610 FOR X=1 TO month
620 READ months
630 NEXT X
640 PRINT month$ ; " ";year;"
650 PRINT "GMT =
660 IF hour< 1 0 THEN PRINT "
670 PRINT; hour; " : " ;
680 IF minute`=
LIST
257
Purpose
This command makes the computer list whatever program it has in its memory.
It is often used before typing RUN to ensure that there aren’t any typing errors
in the program just entered.
You can list a single line
LIST 280
or a range of lines
LIST 100,450
or the whole program
LIST
LIST , 400 will list all lines up to and including line 400.
LIST 400, will list all lines beyond line 400.
If you have a very long program you may see the whole listing whiz past before
you have time to read it. To stop it, and to make the computer stop at the bottom
of each page you can type CTRL N (while holding down the key marked CTRL
press the letter N). Then type LIST. This is called ‘page mode’ and the computer
stops at the bottom of each page. The next page will be printed when the SHIFT
key is pressed.
To return to ‘scroll mode’ type CTRL O (hold CTRL down while briefly pressing
O). Pressing CTRL and SHIFT together immediately pauses a listing, and
pressing ESCAPE will stop a listing so that corrections can be made to the
program.
If you want a listing on the printer then you can turn the printer on by typing
CTRL B before typing LIST.
To turn the printer off afterwards type CTRL C .
LIST is a command and cannot be used as part of a program or as part of a
multiple statement line.
The layout of programs as listed can be controlled by the command LIS TO (see
next entry). As an option, the computer can be instructed to insert spaces for the
duration of all FOR . . .NEXT and REPEAT. . .UNTIL loops.
258
Examples
LIST
LIST 400
LIST 400,500
LIST , 900
LIST 900,
Description
A command which lists the current program.
Syntax
L I S T [ , ][`