Using Arithmetic Expressions
You can use arithmetic expressions in an exec many different ways. The following
example uses several arithmetic operators to round and remove extra decimal
places from a dollar and cents value.
Example Using Arithmetic Expressions
/****************************** REXX *******************************/
/* This exec computes the total price of an item including sales */
/* tax rounded to two decimal places. The cost and percent of the */
/* tax (expressed as a decimal number) are passed to the exec when */
/* it is run. */
/*******************************************************************/
PARSE ARG cost percent_tax
total = cost + (cost * percent_tax) /* Add tax to cost. */
price = ((total * 100 + .5) % 1) / 100 /* Round and remove */
/* extra decimal places.*/
SAY 'Your total cost is $'price'.'
Exercises - Calculating Arithmetic Expressions
1. What will the following program display on the screen?
Exercise
/***************************** REXX ****************************/
pa=1
ma=1
kids = 3
SAY "There are" pa + ma + kids "people in this family."
2. What is the value of:
a. 6-4+1
b. 6-(4+1)
c. 6*4+2
d. 6*(4+2)
e. 24%5/2
ANSWERS
1. There are 5 people in this family.
2. The values are as follows:
a. 3
b. 1
c. 26
d. 36
e. 2
Comparison Operators
Expressions that use comparison operators do not return a number value as do
arithmetic expressions. Comparison expressions return either a true or false
response in terms of 1 or 0 as follows:
1 True
0 False
Using Expressions
30
z/OS V1R1.0 TSO/E REXX User’s Guide