Advertisement
Guest User

Untitled

a guest
Aug 4th, 2015
156
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.31 KB | None | 0 0
  1. puts "Enter a number:"
  2. num = gets.chomp.to_i
  3.  
  4. num_lop = num % 10
  5.  
  6. case num_lop
  7. when 1
  8. suffix = "st"
  9. when 2
  10. suffix = "nd"
  11. when 3
  12. suffix = "rd"
  13. else
  14. suffix = "th"
  15. end
  16.  
  17. ordinal = num.to_s + suffix
  18.  
  19. if num.between?(11, 13)
  20. puts "That's the #{num}th item!"
  21. else
  22. puts "That's the #{ordinal} item!"
  23. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement