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
else (selection == "k".upcase)will be treated as plainelse. Probably you wantelsifin place.if selection.chomp.downcase == "y"(orif selection.chomp.upcase == "Y").gets.to_sis the same asgets.getsalways returns a string that ends with a newline ("\n"). You needgets.chompto remove that newline.