3

I AM USING RUBY

ERROR: comparison of Integer with String failed (ArgumentError)

puts "Age: "
    age = gets.chomp
    if 0 < age < 130

I want the programm to allow the user to input all the numbers between 0 (not included) and 130 (included). How to do it?

Viktor
  • 2,623
  • 3
  • 19
  • 28
Onionixed
  • 63
  • 1
  • 1
  • 10

1 Answers1

3

The input is a string. Try something like this

puts "Age: "
user_input = gets.chomp
begin
  age = Integer(user_input)
  # your code
rescue ArgumentError
  puts "Age must be an integer"
end
Ursus
  • 29,643
  • 3
  • 33
  • 50