I know this tread is kinda old, but I will post anyway.
K, I think this will work for my roman numeral program, I'm a noobie at this stuff, So I don't fully grasp what it is you said. What am I sposed to do to this code without it crashing? I already took the liberty of making a roman numeral version of this. Also, how do you get rid of the spaces you were talking about tacking on? This one won't need them.
This is for old roman numeral, where you add starting at the biggest number, whether that makes a difference or not. so 9 would be VIIII, and 36 would be XXXVI
CODE
puts 'Place a number for its roman numeral.'
roman={'I'=>1, 'V'=>5, 'X'=>10, 'L'=>50, 'C'=>100, 'D'=>500, 'M'=>1000} .to_s
num=gets.chomp
num.split(//).each { |char| print roman[char].to_s + " " }
puts 'Place a number for its roman numeral.' roman={'I'=>1, 'V'=>5, 'X'=>10, 'L'=>50, 'C'=>100, 'D'=>500, 'M'=>1000}.to_s input=gets.chomp
I also tried
CODE
puts 'Place a number for its roman numeral.'
roman={'I'=>1, 'V'=>5, 'X'=>10, 'L'=>50, 'C'=>100, 'D'=>500, 'M'=>1000} .to_s
num=gets.chomp
num.split(//).each { |char| print roman[char].to_s + " " }
I removed the very last line, it didn't crash, but all it did was repeat back my inputs.
I almost forgot, here is my first attempt at it, it does one exact number at a time like 1000 for M, 10 for X and so forth. I had same problem, it won't take all my input and put in all the numerals. Anyway, here is my failure
CODE
roman = gets.chomp.to_i
if roman == 1
puts 'I'
elsif roman == 5
puts 'V'
elsif roman == 10
puts 'X'
elsif roman == 50
puts 'L'
elsif roman == 100
puts 'C'
elsif roman == 500
puts 'D'
elsif roman == 1000
puts 'M'
puts roman.to_i
end