AMSTRAD cpc 6128 User Instruction page 109

Integrated computer/disc system
Hide thumbs Also See for cpc 6128:
Table of Contents

Advertisement

Here's what we can do instead. As the program takes input of a new name, we'll make
the program check that at least something has been typed in for the value of
N A ME $ ( x ) , in other words, check whether the value of N A ME $ ( x) is an
~empty
string' or not. I F it is, THE N we'll make the program stop taking any more input. Did
you get the clue on how we can do this? Add:
55 IF NAME$(x)='"' THEN 80
80 PRINT "no more input"
Also, so that the program tells you how to stop inputting, add:
47 PRINT "Press [RETURN] to end input"
Now let's write some program to PR I N T the information you've stored, firstly in the
form of a list. Add: .
.
90 FOR x=1 TO 100
100 PRINT NAME$(x);" ";TEL$(x)
110 NEXT
Once again the program doesn't know when to stop, before reaching the lOOth
element of the array, so let's add:
95 IF NAME$(x)="" THEN 120
120 PRINT "list finished"
Line 9 5 detects whether N A M E
$ (
x) is an empty string, and I F so, THE N stops
printing by bypassing lines 1 00 and 11 0.
And so to the next of our requirements. We'll now write some program that searches
for a particular name that you enter. Add:
130 INPUT "find";SEARCH$
140 FOR x=1 TO 100
150 IF INSTR(NAME$(x),SEARCH$)=0 THEN 180
160 PRINT NAME$(x);" ";TEL$(x)
170 END
180 NEXT
190 PRINT "name not found"
run
Chapter 2 Page 4
Beyond Foundations

Advertisement

Table of Contents
loading

Table of Contents

Save PDF