When I input a = 12 and b = 9, it returns "a is less than b"


#1

The instructions were make an if/else statement with at least one elsif. I decided to try incorporating input, but can't figure out why some numbers don't return a correct answer. When I input a = 12 and b = 9, it returns "a is less than b"

print "a is:"
a = gets

print "b is:"
b = gets

if a < b
    print "a is less than b"
elsif a > b
    print "a is greater than b"
else
    print "they are equal"
end

#2

The problem you have, is that when you are using gets, ruby will get the arguments of string. String compare with numbers is asking for trouble (that 12 is lesser then 9) (it compares the first value char of each string, then 1 is less then 9)

i recommend casting your variable to integers:

print "a is:"
a = gets
a = a.to_i
print "b is:"
b = gets
b = b.to_i

if a < b
    print "a is less than b"
elsif a > b
    print "a is greater than b"
else
    print "they are equal"
end

#3

Ah. Thanks! I tried to use only the methods I had learned so far, but I certainly won't forget this now.