![[About]](r:\html\rexxabout.gif)
![[Toc]](r:\html\rexxtoc.gif)
0.9b (c) 1995 Peter Childs
The following is an exercise that will serve as a review of some of the rules used in the previous examples. You are to write a procedure that adds two numbers. Name the procedure ADD.CMD.
Here is a list of what you need to do in this procedure:
1. Identify and describe the REXX procedure. 2. Tell the user to type numbers. 3. Read the numbers typed and put them into system memory. 4. Add two numbers and display the answer on the screen. 5. Tell the interpreter to leave the procedure.
There are many ways to write procedures to accomplish the same task. To make it easier in this procedure, the user is asked for each number separately, then the numbers are added. The following is the thought process you might use to write the procedure for ADD.CMD.
1. First, what identifies a REXX procedure? If you thought of a
comment, you were right.
2. Next, you need to tell the user to enter a number. The SAY
instruction prints a message on your screen.
3. If the number is entered, it needs to be put into computer memory.
The PULL instruction collects a response and puts it in memory.
4. An instruction requesting a second number can look just like the
first instruction; the second number also needs to be put in memory.
5. The next instruction is similar to one in the MATH procedure. In
one statement, it can tell the interpreter to add the two values in
memory and display the sum on your screen. This can be one
instruction. The instruction contains a string and the addition
operation.
6. Finally, the EXIT instruction is used to end the procedure.
7. If you want to test this program, type the procedure listed here and
file it.
/* This procedure adds two numbers */
SAY "Enter the first number."
PULL num1
SAY "Enter the second number."
PULL num2
SAY "The sum of the two numbers is" num1 + num2
EXIT
To test ADD.CMD, type ADD at the OS/2 command prompt and try some numbers. Here is what the procedure should look like when it is run, and your numbers are 3 and 12.
[C:\]ADD Enter the first number. 3 Enter the second number. 12 The sum of the two numbers is 15 [C:\]
Inf-HTML End Run - Successful