lundi 17 juillet 2017

Ruby If Else syntax evaluation

I don't understand why my If else statement doesn't work properly, if I the input 'y' then it evaluates the last part of the if else statement.

puts('give 1: ')
nr1= Integer(gets)
puts('give 2: ')
nr2= Integer(gets)

selection = gets.to_s

if (selection == "y".upcase)
  puts "Result is #{nr1+nr2}"
elsif (selection =="v".upcase)
  puts "Result is #{nr1-nr2}"
else (selection == "k".upcase)
  puts "Result is #{nr1*nr2}"
end

Aucun commentaire:

Enregistrer un commentaire