Ruby no implicit conversion of Fixnum into String (TypeError)
This is because the input from gets.chomp
is a String
. You cannot perform modulo (%
) on a String
. You need to convert it to an integer first.
Try this...
puts 'What is the starting year?'starting_year = gets.chomp.to_iputs 'What is the ending year?'ending_year = gets.chomp.to_iwhile starting_year <= ending_year if starting_year%4 == 0 && (starting_year%100 != 0 && starting_year%400 == 0) puts starting_year end starting_year+=1end
Does that work now?