From: "Nik Z." Date: 2009-11-11T09:46:31+09:00 Subject: Re: Roman Numerals (Arrgh!) --00151747bfe2caf3f204780dc156 Content-Type: text/plain; charset=ISO-8859-1 Hi, Rick, I'm not gonna give you the COMPLETE answer to your homework, but think along this line: 1. Split the input number on Non_Word_Boundary (basically split on NOTHING) arrNumber_of_Digits = gets().chomp().to_s.split // This should give your on the digits you have each individually; meaning how many Ones, how many Tens, and how many Hundreds..... And the build your strRoman = "X" * (the corresponding no of digits) 2. Also you will need validate what your professor is going to input in the first place is an integer to begin with, with something like this puts "Invalid input" unless ARGV[0]=~ /^\d+$/ On Tue, Nov 10, 2009 at 3:56 PM, Rick Barrett wrote: > 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) > -- > Posted via http://www.ruby-forum.com/. > > --00151747bfe2caf3f204780dc156--