Need a bit of help

Discussion in 'Ruby' started by Brian Geds, Nov 11, 2009.

  1. Brian Geds

    Brian Geds Guest

    Hey guys im trying to get this to work but I can't for reason, can you
    look over it and tell me the problem, the first part will work 1-9 but
    when I do the array variable to 1-1000 I cant seem to get it to do it.
    Please Help heres the code

    # def roman_numeral(number)
    # result = ''
    # if number > 5
    # result = 'V' + 'I' * (number - 5)
    # else
    # result = 'I' * number
    # end
    # return result
    # end
    # (1..9).each() do |my_number|
    # puts roman_numeral(my_number)
    # end

    $numerals = [
    [1000, 'M'],
    [500, 'D'],
    [100, 'C'],
    [50, 'L'],
    [10, 'X'],
    [5, 'V'],
    [1, 'I']
    ]
    def roman_numeral(number)
    $numerals.each do |decimal, numeral|
    # do something interesting with each decimal, numeral pair
    end
    end
    (1..49).each() do |my_number|
    puts roman_numeral(my_number)
    end
    --
    Posted via http://www.ruby-forum.com/.
    Brian Geds, Nov 11, 2009
    #1
    1. Advertising

  2. On Nov 10, 2009, at 10:10 PM, Brian Geds wrote:

    > Hey guys im trying to get this to work but I can't for reason, can you
    > look over it and tell me the problem, the first part will work 1-9 but
    > when I do the array variable to 1-1000 I cant seem to get it to do it.


    Looks like we have another kid with the same homework. It is becoming prett=
    y popular here ;-). Please look through yesterday's subjects to find a rele=
    vant discussion. Or even better -- think harder for yourself.

    Gennady.


    > Please Help heres the code
    >=20
    > # def roman_numeral(number)
    > # result =3D ''
    > # if number > 5
    > # result =3D 'V' + 'I' * (number - 5)
    > # else
    > # result =3D 'I' * number
    > # end
    > # return result
    > # end
    > # (1..9).each() do |my_number|
    > # puts roman_numeral(my_number)
    > # end
    >=20
    > $numerals =3D [
    > [1000, 'M'],
    > [500, 'D'],
    > [100, 'C'],
    > [50, 'L'],
    > [10, 'X'],
    > [5, 'V'],
    > [1, 'I']
    > ]
    > def roman_numeral(number)
    > $numerals.each do |decimal, numeral|
    > # do something interesting with each decimal, numeral pair
    > end
    > end
    > (1..49).each() do |my_number|
    > puts roman_numeral(my_number)
    > end
    > --=20
    > Posted via http://www.ruby-forum.com/.
    >=20
    Gennady Bystritsky, Nov 11, 2009
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Adrian Inman
    Replies:
    1
    Views:
    2,847
    Adrian Inman
    Feb 24, 2006
  2. Weng Tianxiang
    Replies:
    36
    Views:
    3,441
    Brannon
    Jul 15, 2006
  3. Replies:
    3
    Views:
    1,743
    Timothy Bendfelt
    Jan 19, 2007
  4. Replies:
    9
    Views:
    968
    Juha Nieminen
    Aug 22, 2007
  5. Jeff.M
    Replies:
    6
    Views:
    172
    Lasse Reichstein Nielsen
    May 4, 2009
Loading...

Share This Page