[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.ruby

99 bottles countdown

Calvin

5/27/2009 1:10:00 AM

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
1 Answer

Calvin

5/27/2009 1:53:00 AM

0

On May 26, 6:10 pm, Calvin <cstephe...@gmail.com> 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.