I'm working on a script that asks the user for a year. I know that the portion of code that asks for the year and evaluates the year works, I know that the question evaluates correctly. But when I add them together I get an error.
Please help
def again?
while true
print "Would you like to play again? [y/n]: "
case gets.strip
when 'Y', 'y', 'j', 'J', 'yes' #j for Germans (Ja)
puts "Enter the year: "
STDOUT.flush
input_year = gets.chomp.to_i
if ((input_year % 4 == 0) && (input_year % 100 > 0)) || (input_year % 400 == 0)
puts "Year #{input_year} is a leap year"
else
puts "Year #{input_year} is not a leap year"
end
when /\A[nN]o?\Z/ #n or no
break
end
end
end
again?
Aucun commentaire:
Enregistrer un commentaire