EasyManua.ls Logo

Sinclair QL - Page 110

Sinclair QL
135 pages
Print Icon
To Next Page IconTo Next Page
To Next Page IconTo Next Page
To Previous Page IconTo Previous Page
To Previous Page IconTo Previous Page
Loading...
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.

Other manuals for Sinclair QL

Related product manuals