R
Rick Barrett
I have a homework assignment where I have to convert an inputted integer
into Roman Numerals. I was doing fine building upon the previous steps
until the arrays came in. We have to use the format/guidelines the
professors give us or we get points counted off. I've looked at so many
ways to do this program through Google, but none of the examples I've
seen are even close to what the professor wrote out.
Basically, in my code I have to use the array $numerals and create pairs
with the integer and its corresponding Roman Numeral.
What I can't figure out how to do is say something like...
For each 10 of the inputted number put an X
I was thinking something along the lines of dividing the inputted number
by the decimal and taking the remaining integer and multiplying the
Roman Numeral by that integer.
Like 30/10 = 3 so "X" * 3 would print out XXX
But I have no idea how to do that with the $numerals array.
How do I get my program to say divide the inputted number by the decimal
part of the pair and then give the numeral part that many times?
def roman_numeral(number)
$numerals = [[10, "X"],
[5, "V"],
[1, "I"]]
result = ""
$numerals.each() do |decimal, numeral|
result = new_variable
end
return result
end
puts "Enter a number to be converted to Roman Numerals."
my_number = gets().chomp().to_i()
puts roman_numeral(my_number)
into Roman Numerals. I was doing fine building upon the previous steps
until the arrays came in. We have to use the format/guidelines the
professors give us or we get points counted off. I've looked at so many
ways to do this program through Google, but none of the examples I've
seen are even close to what the professor wrote out.
Basically, in my code I have to use the array $numerals and create pairs
with the integer and its corresponding Roman Numeral.
What I can't figure out how to do is say something like...
For each 10 of the inputted number put an X
I was thinking something along the lines of dividing the inputted number
by the decimal and taking the remaining integer and multiplying the
Roman Numeral by that integer.
Like 30/10 = 3 so "X" * 3 would print out XXX
But I have no idea how to do that with the $numerals array.
How do I get my program to say divide the inputted number by the decimal
part of the pair and then give the numeral part that many times?
def roman_numeral(number)
$numerals = [[10, "X"],
[5, "V"],
[1, "I"]]
result = ""
$numerals.each() do |decimal, numeral|
result = new_variable
end
return result
end
puts "Enter a number to be converted to Roman Numerals."
my_number = gets().chomp().to_i()
puts roman_numeral(my_number)