dish(3)
Procedures
and
Functions
90
3.
Pass
the three numbers
to
a procedure, walter, which passes back the cost
of
the order
to
the main program using a parameter cost. Procedure waiter calls
two
other procedures, compute and cook, which compute the cost and simulate
'cooking':
4.
The
procedure, cook, simply prints
the
number required and
the
name
of
each
dish.
The
main
program should
call
procedures
as
necessary,
get the
total
cost
from
procedure,
walter, 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,
n,
price(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
ll
,
3.5,
IlChicken",
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
di
sh
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,
bi
LL
330
DEFine
PROCedure
waiter(dish,
cost)
340
compute
dish,
cost
350
cook
di
sh
360
END
DEFi ne
The
walter passes the information about the number
of
each dish reqUired
to
the
procedure,
compute, which computes the cost and returns It
12/84
•
•
•
•