Sinclair QL Beginner's Manual page 110

Hide thumbs Also See for QL:
Table of Contents

Advertisement

The main program should call procedures as necessary, get the total cost from procedure, waiter add
10% for a tip, and print the amount of the total bill.
DESIGN
This program illustrates parameter passing in a fairly complex way and we will explain the program
step by step before putting it together.
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
-
-
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
-
-
-
490 DATA "Prawns", 3.5, "Chicken", 2.8, "Special" ,3.3
The names of menu items and their prices are placed in the arrays item$ and price.
The next step is to choose a menu number for each of the six customers. The tally of the number of
each dish required will be kept in the array dish.
160 choose dish
-
-
-
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
Note that the formal parameter dish is both:
local to procedure choose
an array in main program
The three values are passed back to the global array also called dish. These values are then passed
to the procedure waiter.
170 waiter dish, bill
-
-
330 DEFine PROCedure waiter (dish, cost)
340
compute dish,cost
350
cook dish
360 END DEFine
The waiter passes the information about the number of each dish required to the procedure, compute,
which computes the cost and returns it.

Advertisement

Table of Contents
loading

Table of Contents