Amiga World Official AmigaDOS 2 Companion - eBook-ENG

Page 334

316

AmigaWorld Official AmigaDOS 2 Companion command lets you create far more general and useful programs. Compare the following program with the Miles Per Gallon program used above. /* Son of Miles Per Gallon*/ say 'The Automatic Mileage Calculator' say 'Enter distance traveled' pull distance say 'Enter gasoline consumed' pull gallons say 'Enter price per gallon' pull price

/* enter the distance */

/* enter fuel consumed */ /* enter price of gas */

say

mpg = distance / gallons ppm = (gallons * price) / distance

say 'Your car got' mpg 'miles per gallon on this trip.' say 'You paid ' ppm 'cents per mile.' The most important difference between the two programs is their versatility. The first program calculated the mpg and ppm for one trip only. To change the variables, you have to change the program. The second program pauses to let you enter values for its variables from the keyboard as the program runs. You can use it to calculate your mileage and costs for any trip, making it a much more general and useful program.

The pull instruction is actually a special case of the more general parse instruc tion, which lets you manipulate strings in many different ways. Pull takes its input from the keyboard and, if the input is text, converts any lowercase char acters to uppercase. In default mode, pull simply waits for you to enter data at the cursor. You can set a prompt for pull by using the options instruction. For example,

options prompt 'Enter input:'

will display Enter input:

Whenever your program uses the pull command.

Branching Instructions If all a programming language could do was execute instructions serially from the top of the program to the bottom, they wouldn't be of much use. A pro-


Issuu converts static files into: digital portfolios, online yearbooks, online catalogs, digital photo albums and more. Sign up and create your flipbook.