How to resolve the algorithm Integer comparison step by step in the REXX programming language

Published on 12 May 2024 09:40 PM

How to resolve the algorithm Integer comparison step by step in the REXX programming language

Table of Contents

Problem Statement

Get two integers from the user. Then,   display a message if the first integer is: the second integer.

Test the condition   for each case separately,   so that   all three comparison operators are used   in the code.

Let's start with the solution:

Step by Step solution about How to resolve the algorithm Integer comparison step by step in the REXX programming language

Source code in the rexx programming language

/*REXX program  prompts  for  two integers,   compares them,  and  displays the results.*/
numeric digits 2000                              /*for the users that really go ka─razy.*/
@=copies('─', 20)                                /*eyeball catcher for the user's eyen. */
a=getInt(@  'Please enter your 1st integer:')    /*obtain the 1st integer from the user.*/
b=getInt(@  'Please enter your 2nd integer:')    /*   "    "  2nd    "      "   "    "  */
say
      if a
      if a=b  then say  @   a    ' is equal to '         b
      if a>b  then say  @   a    ' is greater than '     b
exit                                             /*stick a fork in it,  we're all done. */
/*──────────────────────────────────────────────────────────────────────────────────────*/
getInt:       do forever;     say                /*keep prompting the user until success*/
                              say arg(1)         /*display the prompt message to console*/
              parse pull x                       /*obtain  X,  and keep its case intact.*/
                 select
                 when x=''               then call serr "No argument was entered."
                 when words(x)>1         then call serr 'Too many arguments entered.'  x
                 when \datatype(x, 'N')  then call serr "Argument isn't numeric:"      x
                 when \datatype(x, 'W')  then call serr "Argument isn't an integer:"   x
                 otherwise    return x           /* [↑]  Eureka!   Return # to invoker. */
                 end   /*select*/
              end      /*forever*/
/*──────────────────────────────────────────────────────────────────────────────────────*/
serr:  say @  '***error*** '    arg(1);        say @  "Please try again.";          return

  

You may also check:How to resolve the algorithm Break OO privacy step by step in the Sidef programming language
You may also check:How to resolve the algorithm Element-wise operations step by step in the C++ programming language
You may also check:How to resolve the algorithm Count occurrences of a substring step by step in the Dyalect programming language
You may also check:How to resolve the algorithm Increment a numerical string step by step in the PowerShell programming language
You may also check:How to resolve the algorithm 99 bottles of beer step by step in the Raku programming language