hi iv just started to learn ruby 2 days ago and have no programing exp
so sorry if this is a stupid question
what i want to do is have some thing happen depending on the exact word
or number the user imputs hears an exampel
puts "what is 2=2 "
input=gets
if
#the user presses 2 then
puts "correct"
else
puts "wrong"
what would i put in the # section or is it more complicated than this
thanks
···
--
Posted via http://www.ruby-forum.com/.
puts "what is 2+2 "
sorry this is what i ment
···
--
Posted via http://www.ruby-forum.com/\.
Having a little bit of difficulty following, I assume you meant "if the user
*enters* *4*, then tell them they did it correctly".
In which case you could have it like this:
print "2 + 2 = "
input = gets.chomp # chomp removes the newline from pressing the enter key
if input == '4' # remember input comes in as a String, so we compare to
String representation of 4
puts 'correct'
else
puts 'wrong'
end
···
On Sun, May 16, 2010 at 10:35 AM, Mark Kirby <mark42@live.co.uk> wrote:
hi iv just started to learn ruby 2 days ago and have no programing exp
so sorry if this is a stupid question
what i want to do is have some thing happen depending on the exact word
or number the user imputs hears an exampel
puts "what is 2=2 "
input=gets
if
#the user presses 2 then
puts "correct"
else
puts "wrong"
what would i put in the # section or is it more complicated than this
thanks
--
Posted via http://www.ruby-forum.com/\.
yhea i did sorry bin at this for hours thanks mate
···
--
Posted via http://www.ruby-forum.com/.