Sinclair QL Beginner's Manual page 111

Hide thumbs Also See for QL:
Table of Contents

Advertisement

370 DEFine PROCedure compute(dish, total)
380
LET total = 0
390
FOR k = 1 to 3
400
LET total = total + dish(k)*price(k)
410
END FOR k
420 END DEFine
The waiter also passes information to the cook who simply prints the number required for each menu
item.
430 DEFine PROCedure cook(dish)
440
FOR c = 1 TO 3
450
PRINT ! dish(c) ! item$(c) !
460
END FOR c
470 END DEFine
Again, the array dish in the procedure cook is local. It receives the information which the procedure
uses in its PRINT statement.
The complete program is listed below.
100 REMark Procedures
110 RESTORE 490
120 DIM item$(3,7),price(3),dish(3)
130 REMark *** PROGRAM ***
140 LET tip = 0.1
150 set_up
160 choose dish
170 waiter dish,bill
180 LET bill = bill + tip*bill
190 PRINT "Total cost is £" ; bill
200 REMark *** PROCEDURE DEFINITIONS ***
210 DEFine PROCedure set_up
220
FOR k = 1 TO 3
230
READ item$(k)
240
READ price(k)
250
END FOR k
260 END DEFine
270 DEFine PROCedure choose(dish)
280
FOR pick = 1 TO 6
290
LET number = RND(1 TO 3)
300
LET dish(number) = dish(number) + 1
310
END FOR pick
320 END DEFine
330 DEFine PROCedure waiter(dish,cost)
340
compute dish,cost
350
cook dish
360 END DEFine
370 DEFine PROCedure compute(dish,total)
380
LET total = 0
390
FOR k = 1 TO 3
400
LET total = total + dish(k)*price(k)
410
END FOR k
420 END DEFine
430 DEFine PROCedure cook(dish)
440
FOR c = 1 TO 3
450
PRINT ! dish(c) ! item$(c)
460
END FOR c
470 END DEFine
480 REMark *** PROGRAM DATA ***

Advertisement

Table of Contents
loading

Table of Contents