View previous topic :: View next topic
|
Author |
Message |
raghavmcs
Active User
Joined: 14 Jul 2005 Posts: 105
|
|
|
|
Dear Experts,
I do not have much knowledge of REXX.If someone can give me a piece of code for following will be great.
a)Say 123456789 is a ninie digit number.I want this number to be taken from the user and then
Getting the second last digit like in this case its 8.
Next step is adding 1 to it which maked 9 in this case
Display the outout 9 in this case
But there is an exception of output and that is for
when the second digit from last is 9.IN this case 9+1 will make 10.But in this case the output should be 0.
I know that its easy task for someone who knows REXX.I have to get this done urgently and my current REXX skill are not helping me out to get this.
Hope I am not bugging any of the experts here,thanks |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
|
|
homework ??
what did You try, up to now,,,
post something ( even errors ) and somebody will be glad to advice |
|
Back to top |
|
|
raghavmcs
Active User
Joined: 14 Jul 2005 Posts: 105
|
|
|
|
I tried Stem concept.Bust stuck next,anyway I feel like you want me to learn REXX and be the expert :-) |
|
Back to top |
|
|
raghavmcs
Active User
Joined: 14 Jul 2005 Posts: 105
|
|
|
|
I was trying like this.Please do not see the digits and the number of digits.
Not sure am on right track to achieve this
VAR1=RIGHT( '102301123',2)
VAR2=RIGHT('VAR1',1)
VAR3=VAR2+1
SAY VAR1
SAY VAR2
SAY VAR3 |
|
Back to top |
|
|
enrico-sorichetti
Superior Member
Joined: 14 Mar 2007 Posts: 10873 Location: italy
|
|
|
|
first of all, where did the assignment come from ??
( it does not make too much sense ) |
|
Back to top |
|
|
Douglas Wilder
Active User
Joined: 28 Nov 2006 Posts: 305 Location: Deerfield IL
|
|
|
|
It look like you are coming along fine on coding this.
To be on the safe side it is good for the first line of a REXX to contain /* REXX */.
If you need to get the input from the keyboard try using "Parse Upper Arg".
For your exception processing use an "IF THEN ELSE".
There is no batter way to learn any programming language than to try it, and when needed get pointers (not the answers) from someone else who knows the language. |
|
Back to top |
|
|
expat
Global Moderator
Joined: 14 Mar 2007 Posts: 8797 Location: Welsh Wales
|
|
|
|
raghavmcs wrote: |
I was trying like this.Please do not see the digits and the number of digits.
Not sure am on right track to achieve this
VAR1=RIGHT( '102301123',2)
VAR2=RIGHT('VAR1',1)
VAR3=VAR2+1
SAY VAR1
SAY VAR2
SAY VAR3 |
Unfortunately, the syntax is almost correct but the logic is not. The logic will return the LAST digit from the string.
Syntax - Where you have VAR2=RIGHT('VAR1',1) by enclosing the word VAR1 in quotes you are using a literal rather than the value stored in the VAR1 variable.
Logic - Try this
Code: |
VAR2 = LEFT(VAR1,1)
VAR3 = VAR2 + 1
IF VAR3 > 9 THEN VAR3 = 0
|
|
|
Back to top |
|
|
ofer71
Global Moderator
Joined: 27 Dec 2005 Posts: 2358 Location: Israel
|
|
|
|
Another version:
Code: |
/* REXX */
A = '123456789'
B = RIGHT(SUBSTR(REVERSE(STRIP(A)),2,1)+1,1)
SAY A
SAY B
EXIT
|
O. |
|
Back to top |
|
|
Pedro
Global Moderator
Joined: 01 Sep 2006 Posts: 2547 Location: Silicon Valley
|
|
|
|
O.'s example works. But in instances like this, I prefer using the PARSE instruction:
Code: |
/* REXX */
A = '123456789'
PARSE VAR a 8 b 9 .
SAY A
SAY B
EXIT |
|
|
Back to top |
|
|
|