Created
February 21, 2011 19:19
-
-
Save korutsuru/837549 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#programa que cambia numeros a letras, si le ponen 11 les dira que es teenone u 12 teentwo pero no se fijen xD | |
#variables____________________________________________________________________ | |
number=String.new | |
#methods______________________________________________________________________ | |
def onedigit (number) | |
x = case number | |
when 0 then '' | |
when 1 then 'one' | |
when 2 then 'two' | |
when 3 then 'three' | |
when 4 then 'four' | |
when 5 then 'five' | |
when 6 then 'six' | |
when 7 then 'seven' | |
when 8 then 'eight' | |
when 9 then 'nine' | |
end | |
return x | |
end | |
def twodigits (number) | |
x = case number | |
when 1 then 'teen' | |
when 2 then 'twenty' | |
when 3 then 'thirty' | |
when 4 then 'fourty' | |
when 5 then 'fifty' | |
when 6 then 'sixty' | |
when 7 then 'seventy' | |
when 8 then 'eighty' | |
when 9 then 'ninethy' | |
end | |
return x | |
end | |
#BODY____________________________________________________________________________________________ | |
p 'enter a number: ' | |
myarray = gets.chomp.split(//).reverse! | |
myarray.each_with_index{|item,count| | |
if count == 0 then | |
number=number + onedigit(item.to_i) | |
elsif count == 1 then | |
number=number.insert(0,twodigits(item.to_i)) | |
elsif count == 2 then | |
number=number.insert(0,"#{onedigit(item.to_i)}hundred ") | |
elsif count == 3 then | |
number=number.insert(0,"#{onedigit(item.to_i)}thousand ") | |
elsif count == 3 then | |
number=number.insert(0,"#{onedigit(item.to_i)}million ") | |
end | |
} | |
puts number |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment