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

10INPUT “ENTER THE CELSIUS TEMP”;C

20GOSUB 500

30INPUT “ENTER THE FAHRENHEIT TEMP”;F

40GOSUB 600

50END

500F=(C*9/5)+32

510PRINT “THE FAHRENHEIT TEMP IS”;F

520RETURN

600C=(F-32)*5/9

610PRINT “THE CELSIUS TEMP IS”;C

630RETURN

RUN

46