Exercises - Using SELECT WHEN…OTHERWISE…END

About this task

"Thirty days hath September, April, June, and November; all the rest have thirty-one, save February alone ..."

Write a program that uses the input of a number from 1 to 12, representing the month, and produces the number of days in that month. Assume the user specifies the month number as an argument when calling the program. (Include in the program an ARG instruction to assign the month number into the variable month). Then have the program produce the number of days. For month 2, this can be 28 or 29.

ANSWER
Figure 1. Possible Solution
/******************************** REXX *******************************/
/* This program uses the input of a whole number from 1 to 12 that   */
/* represents a month.  It produces the number of days in that       */
/* month.                                                            */
/*********************************************************************/

 ARG month

 SELECT
   WHEN month = 9 THEN
     days = 30
   WHEN month = 4 THEN
     days = 30
   WHEN month = 6 THEN
     days = 30
   WHEN month = 11 THEN
     days = 30
   WHEN month = 2 THEN
     days = '28 or 29'
   OTHERWISE
     days = 31
 END

 SAY 'There are' days 'days in Month' month'.'

Task Task

Feedback


Timestamp icon Last updated: Tuesday, 7 January 2014


http://pic.dhe.ibm.com/infocenter/cicsts/v5r1/topic/com.ibm.cics.rexx.doc//dfhrx/dfhrx00042.html