Download TSO/E REXX User's Guide

Transcript
Writing a Subroutine
Possible Solution (Internal Subroutine named CHECK)
check:
/\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\/
/\ This internal subroutine checks for valid input of "HEADS",
\/
/\ "TAILS", or "QUIT". If the user entered anything else, the
\/
/\ subroutine tells the user that it is an invalid response and
\/
/\ asks the user to try again. The subroutine keeps repeating
\/
/\ until the user enters valid input. Information is returned to \/
/\ the main exec through commonly used variables.
\/
/\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\/
DO UNTIL outcome = 'correct'
SELECT
WHEN response = 'HEADS' THEN
outcome = 'correct'
WHEN response = 'TAILS' THEN
outcome = 'correct'
WHEN response = 'QUIT' THEN
EXIT
OTHERWISE
outcome = 'incorrect'
SAY "That's not a valid response. Try again!"
SAY "Heads, tails, or quit?"
PULL response
END
END
RETURN
Possible Solution (External Subroutine named THROW)
/\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\ REXX \\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\/
/\ This external subroutine receives the valid input from the user,\/
/\ analyzes it, gets a random "throw" from the computer and
\/
/\ compares the two values. If they are the same, the user wins. \/
/\ If they are different, the computer wins. The outcome is then \/
/\ returned to the calling exec.
\/
/\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\\/
ARG input
IF input = 'HEADS' THEN
userthrow = ð
/\ heads = ð \/
ELSE
userthrow = 1
/\ tails = 1 \/
compthrow = RANDOM(ð,1)
IF compthrow = userthrow THEN
outcome = 'human'
ELSE
outcome = 'machine'
RETURN outcome
6-10
OS/390 V1R2.0 TSO/E REXX User's Guide
/\ choose a random number between \/
/\ ð and 1 \/
/\ user chose correctly
\/
/\ user didn't choose correctly
\/