30 number=VAL(mixture$)
40 IF number>0 THEN PRINT "The string begins with the numbers ";
number
If a string begins with numeric characters, a + or -- sign, VAL converts those
characters to their numeric equivalent. Note that VAL ignores the remainder
of the string following the first non-numeric character it discovers, for example:
PRINT VAL("123g456")
produces 123.
READ, DATA and RESTORE
Many programs need some basic data before they can run, and it is often
convenient to store that data as part of the program. For example, here is a
simple quiz program that includes the questions and answers in DATA
statements:
10 MODE 135
20 PR0Cstart
30 PROCquiz
40 END
50 DEFPROCstart
60 correct=0
70 READ how_many
80 PRINT TAB( 14) "A quiz game"
90 PRINTSTRING$(4,"=")
100 ENDPROC
110 DEFPR0Cquiz
120 FOR question=1 TO how_many
130 READ question$,answer$
140 PRINT'question$
150 INPUT response$
160 IF response$=answer$ THEN PR0Cright ELSE PR0Cwrong
170 NEXT question
180 PRINT '"You had " ;correct;" right out of ";how_many
190 ENDPROC
200 DEFPROCright
210 correct=correct+1
220 IF RND(2) >1 THEN PRINT '"That's right ! " ELSE PRINT '"Well done! "
230 ENDPROC
240 DEFPR0Cwrong
250 PRINT' "No, the answer is:"
260 PRINTanswer$
270 ENDPROC
C 50