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
On Sun, May 16, 2010 at 10:35 AM, Mark K. [email protected] wrote:
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/.
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
yhea i did sorry bin at this for hours thanks mate