crouse wrote:
I would take each number your going to convert and (split) it into 2 parts......
x would equal the original number
y would equal the LAST digit in the number
z would equal all the digits MINUS the last number
do this with CUT and $#
so x = $(z)$(y)
then I would use some if/then statements to convert $(y)
if $y = 1 then $y = "1st"
if $y = 2 then $y ="2nd"
That should get you started I think
And of course, that's the beauty of development -- there's usually more than one way to do it.
In my case, I'd only split off the last two numbers (if the string is >= 2 digits) and use them to determine what suffix to append to the original string. Using Crouse's notation:
Code:
where w = unused digits > 99
and x' is the final string
x = $(w)$(z)$(y)
# apply case and/or if/else statements here to determine suffix ($(suf))
x' = $(w)$(z)$(y)$(suf)
Bear in mind that x may not have been changed ever, simply its y and z values extracted for testing (possibly to another variable).
An example might be: x = 112
$(w) = 1, $(z) = 1, $(y) = 2
# magic happens here :)
x' = 112th
My suggestion to thinking about the problem is to take a moment, step back, and think about how you can generalize the ordinal numbering system. Are there any rules that you can identify as to what suffix goes on which numbers? Find patterns and code to solve those patterns.
I find it's easiest to clearly understand what you have to do and what exceptions there are (for your various test cases) before I start hacking out code. Little code tests are fine during this stage to understand the language and then you piece the little parts into a larger whole script.