st, nd, rd number suffixes in 'else if else'

I'm writing a program to read off floor numbers in a hotel among other things. I'm trying to write in code that outputs 'st' 'nd' & 'th' if the floor has the (1), (2), (3) in the first spot above the decimal, not just for floors 1-10, or even 1-100, but for as many multiples as the user inputs. Anyone have a way of doing this more elegantly than if (floorCount == 1 || floorCount == 21 || floorCount ==31 || floorCount == 41, etc. ad nauseum... Thanks for any response!
1
2
3
4
5
6
7
8
if (floorCount % 10 == 1)
// st
else if (floorCount % 10 == 2)
// nd
else if (floorCount % 10 == 3)
// rd
else
// th 


Modulus is your friend.
Modulus is my friend. Freddy, thanks a lot!:)
Heh, genius. I like it. Great little snippet to have handy.
Topic archived. No new replies allowed.