99 bottles countdown

Discussion in 'Ruby' started by Calvin, May 27, 2009.

  1. Calvin

    Calvin Guest

    Hi,

    I am a beginner trying to write a Ruby program that mimics the song
    - '99 bottles of beer on the wall'. I want the program to ask 'how
    many bottles...' on the wall, subract 1 from that number, and then ask
    the question again until it gets down to 1 bottle of beer on the wall.
    So far can only get the program to subtract the number once and then
    the program stops. Any hints, suggestions, or reccomendations to a
    page/chapter in the 'Programming Ruby 1.8' book would be greatly
    appreciated. Here is the Ruby code I put together so far:

    question = 'how many bottles of beer on the wall?'
    puts question
    x = gets.chomp
    y = x .to_i - '1' .to_i
    response = y .to_s + ' bottles of beer on the wall'

    if y != 1
    puts response
    puts question
    end


    Thanks for your time,

    Calvin
     
    Calvin, May 27, 2009
    #1
    1. Advertising

  2. Calvin

    Calvin Guest

    On May 26, 6:10 pm, Calvin <> wrote:
    >   Hi,
    >
    >   I am a beginner trying to write a Ruby program that mimics the song
    > - '99 bottles of beer on the wall'. I want the program to ask 'how
    > many bottles...' on the wall, subract 1 from that number, and then ask
    > the question again until it gets down to 1 bottle of beer on the wall.
    > So far can only get the program to subtract the number once and then
    > the program stops. Any hints, suggestions, or reccomendations to a
    > page/chapter in the 'Programming Ruby 1.8' book would be greatly
    > appreciated. Here is the Ruby code I put together so far:
    >
    >   question = 'how many bottles of beer on the wall?'
    >   puts question
    >   x = gets.chomp
    >   y = x .to_i - '1' .to_i
    >   response = y .to_s + ' bottles of beer on the wall'
    >
    >   if y != 1
    >   puts response
    >   puts question
    >  end
    >
    >   Thanks for your time,
    >
    >   Calvin


    I should have searched for similar projects in the group discussions-
    found my answer... kind of. Sorry to bother you guys.
     
    Calvin, May 27, 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. Ryan Stewart

    GUI countdown timer in a JApplet?

    Ryan Stewart, Dec 23, 2003, in forum: Java
    Replies:
    2
    Views:
    896
  2. vasilis

    Countdown

    vasilis, Aug 23, 2004, in forum: Java
    Replies:
    2
    Views:
    701
    Nick Pomfret
    Aug 23, 2004
  3. Replies:
    5
    Views:
    582
    Andrew Thompson
    Nov 30, 2004
  4. Materialised

    [OT]99 Bottles of Beer

    Materialised, Aug 10, 2004, in forum: C Programming
    Replies:
    2
    Views:
    328
    CBFalconer
    Aug 11, 2004
  5. danielj
    Replies:
    10
    Views:
    293
    Michael Morin
    Aug 28, 2008
Loading...

Share This Page