M
Mica Koizumi
I am teaching myself Ruby and am trying to figure out why this program
is doing what it is doing:
puts 'Year 1?'
year1 = gets.chomp
puts 'Year 2?'
year2 = gets.chomp
while (year1.to_i <= year2.to_i)
if year1.to_i % 4 == 0
leapyear = year1.to_i + 4
puts leapyear
end
if year1.to_i % 4 != 0
year1 = year1.to_i + 1
puts year1
end
end
When year1 = 1987 and year2 = 1990, why is it printing out 1992? I am
expecting 1988.
Thanks in advance...
is doing what it is doing:
puts 'Year 1?'
year1 = gets.chomp
puts 'Year 2?'
year2 = gets.chomp
while (year1.to_i <= year2.to_i)
if year1.to_i % 4 == 0
leapyear = year1.to_i + 4
puts leapyear
end
if year1.to_i % 4 != 0
year1 = year1.to_i + 1
puts year1
end
end
When year1 = 1987 and year2 = 1990, why is it printing out 1992? I am
expecting 1988.
Thanks in advance...