- #1
completenewbie
- 5
- 0
Hi, its my first post, so don't be too hard on me. Here's my dilemma:
I'm trying to write a computer program, to return a number with it's apropriate suffix. (ie: 1=1st, 2=2nd, 3=3rd, etc.) Forget the programming aspect for a minute, all I'm interested in is the logic. If X=answer, I can integer divide (mod) X by 10 and I get a number between 0 and 9 (ie: 21mod10=1, 33mod10=3, 40mod10=0, etc.). Then I can assign 1= st, 2=nd, 3=rd, and everything else=th. The logic works except for 11, 12, and 13. Using this logic, I get 11st, 12nd, and 13rd. How can I modify my logic to make it work?
I'm trying to write a computer program, to return a number with it's apropriate suffix. (ie: 1=1st, 2=2nd, 3=3rd, etc.) Forget the programming aspect for a minute, all I'm interested in is the logic. If X=answer, I can integer divide (mod) X by 10 and I get a number between 0 and 9 (ie: 21mod10=1, 33mod10=3, 40mod10=0, etc.). Then I can assign 1= st, 2=nd, 3=rd, and everything else=th. The logic works except for 11, 12, and 13. Using this logic, I get 11st, 12nd, and 13rd. How can I modify my logic to make it work?