VTech Precomputer Power Pad Plus User Manual

Page 50

Advertising
background image

46

MORE ABOUT GROUPS - GOSUB ... RETURN

How much is 10 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 converting Fahrenheit to Celsius is:

C=(F-32)*5/9

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)*5/9

610 PRINT “THE CELSIUS TEMP IS”;C

630 RETURN

RUN

Advertising