Download Print this page

Radio Shack TRS-80 model III Owner's Manual page 108

Mini-disk operation, trsdos disk operating system, disk basic programming language
Hide thumbs Also See for TRS-80 model III:

Advertisement

DISK BASIC
Examples
DEF FNR(AtB)
=
A
+
INT((B
-
(A
-
1))
*
RND<0>>
This statement
defines function
fnr which
returns a
random number
between
integers
A
and
B.
The
values
for
A
and
B
are
passed
when
the function
is
"called,"
i.e.,
used
in
a
statement
like:
Y
=
FNR(R1
*
R2)
If
ri
and
R2
have been
assigned
the
values
2 and
8, this line
would
assign a
random number
between
2
and
8
to
y.
DEF FNL$(K)
=
STRING*(Xf
"-")
Defines function
fnl$
which
returns a
string
of
hyphens,
x
characters long.
The
value
for
x
is
passed
when
the function
is
called:
PRINT FNL$<3)
This
line prints
a
string
of
30 hyphens.
Here's
an
example showing def fn
used
for a
complex
computation
in
double-precision.
DEF
FNX#(A#*
B#)
=
<A#
-
B»)
*
(A«
-
B«)
Defines function
fnx#
which
returns the
double-precision value of
the
square of
the difference
between
a#
and b#.
The
values
for
a#
and
b#
are
passed
when
the
function
is
called:
S#
=
FNX*(A#>
B«)
We
assume
that
values
for
a#
and
b#
were
assigned elsewhere
in
the
program.
Sample Program
71(3
DEF FNV(T>
=
(1S87
+
SQR(273
+
T))/1G
#
52
720 INPUT "AIR
TEMPERATURE
IN
DEGREES CELSIUS";
T
730 PRINT "THE
SPEED
OF
SOUND
IN
AIR OF"
T
"DEGREES
CELSIUS
IS"
FNV<T)
"FEET PER SECOND*"
107

Advertisement

loading