Each condition can contain only one relational operator. Thus the following condition
is not allowed:
A<>B<>C
It
should be clear that IF/THEN is a very powerful statement because it allows the
program to carry out different tasks and functions, depending upon the value or values
of
numeric expressions.
Experiment
#2
Printing Dollars and Cents
One unsatisfactory aspect
of
the Sales Commision program is that the value printed for
the commission does not directly indicate dollars in the customary fashion.
Run the program and enter the value 1763.89 for the total sales. You will see that
264.5835 is printed out for the amount
of
the commission. The output
of
the program
is a decimal number that sometimes contains more than two digits to the right
of
the
decimal point.
It
would be much neater
if
the commission were printed to the nearest cent each time.
One way
of
accomplishing this is to use a different print statement. Instead
of
using
PRINT, the PRINTUSING statement can be used to format the output.
Make the following changes to the program:
Change line 40 as follows:
40
PRINT
"COMMISSION
IS
";
and add a new line 50
50
PRINTUSING
"####.##";
CM
Line 40 will display the message
COMMISSION
IS
and line 50 will print the value
of
the commission. Now
if
you execute this revised
program you will see that the commission is printed, as desired, rounded to the nearest
cent.
For example, run the program and enter 1763.89 as the sales amount. This time the
commission amount prints as 264.58.
The string enclosed in quotes,
####.##
is called a format specifier, and it indicates how a number is to be printed.
Since two
of
the # symbols appear to the right
of
the decimal point, exactly two
digits will be printed to the right
of
the decimal point.
By
the same token, a maximum
of
four digits to the left will be printed. (Fewer than four digits to the left
of
the
decimal point may
be
printed, depending on the size
of
the number.)
48