mardi 19 janvier 2016

If statement not working with gets() in Ruby

I assume that it's using the gets() that's causing the issue because when I enter

num = 44
if num == 44
    puts "Yeah" 
end
unless num == 44
    puts "No"
end

The output is "Yeah" which is what I expect. However, when I ask the user for input like this:

puts "Enter num: "
num = gets()
if num == 44
    puts "Yeah" 
end
unless num == 44
    puts "No"
end

The output is "No" even though I enter 44 when prompted.

I'm just starting to learn Ruby so I'ms sure that this is a really stupid question... but I really can't figure out what's going on so please help! Thank you so much in advance!

Aucun commentaire:

Enregistrer un commentaire