+ 3
Why doesn't case work with user input if the same number is on the when statement?
I tried to put user input with a case statement woth x = gets and put x next to case uet when I put 5, it didn't output child. https://code.sololearn.com/cWbybdS6U8f1/?ref=app
1 ответ
+ 11
"x = gets" means x will be a string. Replace it with "x = gets.to_i" so that x will be an integer.
x = gets.to_i
case x
when 1, 2, 3
puts "Little baby"
when 4, 5
puts "Child"
end
Above code works.