Comparison Operators - IBM SC34-5764-01 Manual

Cics transaction server for vse/esa
Table of Contents

Advertisement

7 + 2 * 3 - 1
\___/
6
3. Addition and subtraction from left to right
7 + 6 - 1 = 12
Using Arithmetic Expressions
You can use arithmetic expressions in a program many different ways. The following example uses several
arithmetic operators to round and remove extra decimal places from a dollar and cents value.
/****************************** REXX *********************************/
/* This program 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 program
/* when you run it.
/*********************************************************************/
PARSE ARG cost percent_tax
total = cost + (cost * percent_tax)
price = ((total * 100 + .5) % 1) / 100
SAY 'Your total cost is £'price'.'
Figure 11. Example Using Arithmetic Expressions
Exercises—Calculating Arithmetic Expressions
1. What line of output does the following program produce?
/****************************** 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 1, which represents true, or 0, which represents false.
Comparison operators can compare numbers or strings and perform evaluations, such as:
Are the terms equal? (A = Z)
Is the first term greater than the second? (A > Z)
Is the first term less than the second? (A < Z)
/* Add tax to cost.
/* Round and remove extra */
/* decimal places.
Using Variables and Expressions
*/
*/
*/
*/
Chapter 3. Using Variables and Expressions
23

Hide quick links:

Advertisement

Table of Contents
loading

This manual is also suitable for:

Rexx

Table of Contents