puts "Enter the first number"
num1 = Float(gets)
puts "Enter the second number"
num2 = Float(gets)
puts "Enter the operation"
op = gets
op = op.chomp # <--- THIS LINE!
case op
when "+" then puts num1 + num2
when "-" then puts num1 - num2
when "*" then puts num1 * num2
when "/" then puts num1 / num2
end
My code does not work without that specific line. Why?
55 views Asked by Jesus At
1
When entering the "+" operation, you hit two keys, + and return. Both produce a character, resulting in
"+\n". (that\nis a newline character)chompremoves the newline character.