9.
MORE ABOUT GROUPS - GOSUB ... RETURN
How much is 1 O degrees Celsius in Fahrenheit? What is 100 degrees Fahrenheit
in Celsius? Here's a program that gives you the answers
..
It uses the GOSUB
and RETURN statements to create a group of instructions that can be executed
from various parts of the
program.
Remember when you use a
GOSUB,
the
program branches to the line number that you specify in the statements that will
be executed sequentially until a RETURN statement is encountered
.
At that point
the program will resume at the next statement following the GOSUB. Confusing?
Not really, but first some more background about our
problem.
The formula for converting Celsius to Fahrenheit is:
F=(9/5*C)+32
The formula for Fahrenheit to Celsius Is:
C=(F-32)*5l9
Now for the program!
Type:
New
10 INPUT "ENTER THE CELSIUS TEMP" ;C
20 GOSUB 500
30 INPUT "ENTER THE FAHRENHEIT TEMP" ;F
40 GOSUB 600
50 END
500
F=(C*
9/5)+32
510 PRINT "THE FAHRENHEIT TEMP IS";F
520 RETURN
600 C=(F-32)*5l9
610 PRINT "THE CELSIUS TEMP IS";C
630 RETURN
32
Need help?
Do you have a question about the PreComputer 2000 and is the answer not in the manual?