Dave wrote:
JB wrote:
I too wish the author had put examples, say on some pages in the back or
something.
beer = 99
while beer >= 0
beer = beer - 1
endOK, now we’ve got the basic structure of the program - one loop, beer starts
at 99, and decreases until it gets to 0. But there’s no output yet.See how you go putting some flesh on that skeleton, JB - post back when
you’re done.
Hi Dave,
Okay, here’s what I got, and it works too, heh. The ‘if’ had to be in
there,
or else it kept ending with negative numbers (usually -2). This way is
as
good as Bill’s, but a lot shorter (not putting you down or anything
Bill!).
beer = 99
while beer >= 0
beer = beer - 1
if (beer - 1) >= 0
puts beer.to_s + ’ ’ ‘bottles of beer on the wall,’ +
beer.to_s + ’ bottles of beer,’ +
‘take one down, pass it around,’ +
(beer - 1).to_s + ’ ’ + ‘bottles of beer on the wall!’
end
end
Now, to clean it up even more…when it gets down to ‘1 bottle’, I
don’t
want it to say ‘1 bottles…’ (plural). How would I do this? I tried
with an
‘else’ in there, but for some reason I either made it an infinite loop
or it
kept getting the negative numbers all over again.
I tried with an ‘else (beer - 1) == 1’ (no quotes of course and that
didn’t
work either.
I do appreciate all the help you guys are giving, and yes, the
interactive
way will make me work a little harder too to get things right, plus I’m
the
kind who needs that kind of help or I fail miserably and give up, heh.