M
Mike West
Hello all,
I am a complete novice to programming. I have chosen Ruby as my first
language.
I am attempting to follow some tutorials in a book I have. However, I am
running into some errors, and can not figure out why. Can you please
guide me?
It appears I am having trouble mixing both integers with strings. For
example, if I try:
puts 2+4 ' is the sum of 2+4.'
I get an error.
In relation to the current exercise I am doing I am attempting to ask a
user for a number, and then have the computer tell them a bigger number
is better. Below is my attempted code:
puts 'Hello, what is your favorite number?'
number = gets.chomp
better = number.to_i+1
puts number + '?? Don\t you know that ' + better + 'is a superior
selection?'
That does not work though. However if I do:
puts 'Hello, what is your favorite number?'
number = gets.chomp
better = number.to_i+1
puts better
That works. But I would like a string to go along with the answer. How
do you mix arithmetic(or integers) and strings together?
Thank you!
I am a complete novice to programming. I have chosen Ruby as my first
language.
I am attempting to follow some tutorials in a book I have. However, I am
running into some errors, and can not figure out why. Can you please
guide me?
It appears I am having trouble mixing both integers with strings. For
example, if I try:
puts 2+4 ' is the sum of 2+4.'
I get an error.
In relation to the current exercise I am doing I am attempting to ask a
user for a number, and then have the computer tell them a bigger number
is better. Below is my attempted code:
puts 'Hello, what is your favorite number?'
number = gets.chomp
better = number.to_i+1
puts number + '?? Don\t you know that ' + better + 'is a superior
selection?'
That does not work though. However if I do:
puts 'Hello, what is your favorite number?'
number = gets.chomp
better = number.to_i+1
puts better
That works. But I would like a string to go along with the answer. How
do you mix arithmetic(or integers) and strings together?
Thank you!