As I am going through my ruby book (Trying to learn Ruby of course) on
how to use flow control, one of the exercises is to create a program
that sings "99 bottles of beer on the wall"
I have started to create this program and I am at the point where I want
to test what I have done so far (code is not finished). When I try to
run my code, I get the following error:
99bottles.rb:10: syntax error, unexpected tIDENTIFIER, expecting kEND
puts number + ' bottles of beer on the wall, ' number + ' bottles of
beer. Take
^
one down pass it around'
The snipet of code its referring to is:
puts number + ' bottles of beer on the wall, ' number + ' bottles of
beer. Take one down pass it around'
My first thought is that my spacing between the variable "number" and
the "+" sign are screwing things up but I can't seem how since to me
that clearly looks OK.
It could also be that I just don't understand how to properly right a
variable into a string, but to me that also looks right ( I even tried
it with the .to_s and still nothing).
Can anyone help me understand what I am doing wrong?
I'm no ruby expert yet, but I believe the problem is this:
/on the wall, ' number + ' bottles
/which should read
/on the wall, ' + number + 'bottles/
You left out the + after the string and before the "number" variable.
Have fun.
Lovell Mcilwain wrote:
···
Hello all,
As I am going through my ruby book (Trying to learn Ruby of course) on how to use flow control, one of the exercises is to create a program that sings "99 bottles of beer on the wall"
I have started to create this program and I am at the point where I want to test what I have done so far (code is not finished). When I try to run my code, I get the following error:
99bottles.rb:10: syntax error, unexpected tIDENTIFIER, expecting kEND
puts number + ' bottles of beer on the wall, ' number + ' bottles of beer. Take
^
one down pass it around'
The snipet of code its referring to is:
puts number + ' bottles of beer on the wall, ' number + ' bottles of beer. Take one down pass it around'
My first thought is that my spacing between the variable "number" and the "+" sign are screwing things up but I can't seem how since to me that clearly looks OK.
It could also be that I just don't understand how to properly right a variable into a string, but to me that also looks right ( I even tried it with the .to_s and still nothing).
Can anyone help me understand what I am doing wrong?
puts number + ' bottles of beer on the wall, ' number + ' bottles of
beer. Take one down pass it around'
try this instead:
puts number + ' bottles of beer on the wall, ' + number + ' bottles of
beer. Take one down pass it around'
Note the '+ number +' at the second variable call.
best, George
Lovell Mcilwain wrote:
···
Hello all,
As I am going through my ruby book (Trying to learn Ruby of course) on
how to use flow control, one of the exercises is to create a program
that sings "99 bottles of beer on the wall"
I have started to create this program and I am at the point where I want
to test what I have done so far (code is not finished). When I try to
run my code, I get the following error:
99bottles.rb:10: syntax error, unexpected tIDENTIFIER, expecting kEND
puts number + ' bottles of beer on the wall, ' number + ' bottles of
beer. Take
^
one down pass it around'
The snipet of code its referring to is:
puts number + ' bottles of beer on the wall, ' number + ' bottles of
beer. Take one down pass it around'
My first thought is that my spacing between the variable "number" and
the "+" sign are screwing things up but I can't seem how since to me
that clearly looks OK.
It could also be that I just don't understand how to properly right a
variable into a string, but to me that also looks right ( I even tried
it with the .to_s and still nothing).
Can anyone help me understand what I am doing wrong?
I did miss that + sign before the second variable. I can't believe I
missed it. I had been looking at that same piece of code for about 4
hours trying to figure it out and it was so simple
Now that I am still in my testing, I have run into another issue with my
while statement. I am new to programming all together so I am having a
bit of an issue understanding loops in general.
When I tried to run my program this other error has shown up:
Its saying an unexpected end but I can't see where. My "ends" seem to
be fine but I will post the entire while loop, maybe its another simple
thing Im missing again.
number = 99
while input > number
puts number + ' bottles of beer on the wall, ' + number + ' bottles of
beer. Take one down pass it around'
input=gets.chomp
while input > number
if input < number
puts 'No Way! Choose a lower number then ' + number.to_s
else
number = (number.to_i - 1)
end
end
Converting my variables to string got my program to the point where its
asking for my input. Once I put it in, it bails on me with a comparison
error.
99 bottles of beer on the wall, 99 bottles of beer. Take one down pass
it around
98
99bottles.rb:15:in `>': comparison of String with 99 failed
(ArgumentError)
from 99bottles.rb:15
I still believe this has something to do with my starting point problem
and not knowing how to specify it correctly.
Yep I corrected my indenting and noticed it. I did add another end to
the bottom of the program. But Im still not able to run this program.
My lack of a definition of my variable input which isn't defined till
later in a while loop.
Can anyone tell me the best way in this case to define a starting point
and explain why or how it would work? (Have to learn something with all
this)
For example. You must use explicit conversion in most cases in Ruby.
···
On 2006.10.18 11:46, Lovell Mcilwain wrote:
Converting my variables to string got my program to the point where its
asking for my input. Once I put it in, it bails on me with a comparison
error.
99 bottles of beer on the wall, 99 bottles of beer. Take one down pass
it around
98
99bottles.rb:15:in `>': comparison of String with 99 failed
(ArgumentError)
from 99bottles.rb:15