On Thu, Mar 28, 2013 at 1:17 PM, Phil H. <lists / ruby-forum.com> wrote:

> This one is stumping me because of all the variables needed. Only thing
> taught before this challenge was basic branches and loops. This is what
> I have so far.
>
> puts 'Leap Year Calculator'
> puts ' '
> puts 'Enter the starting year.'
> starting_year = gets.chomp
> puts 'Enter the ending year.'
> ending_year = gets.chomp
>
>
The rest doesn't work at all because if you put something like 2096-2104
you would print out 2096, 2100 which is incorrect in two ways

1) 2100 isn't a leap year
2) 2104 should be printed and your second while clause precludes that

You shouldn't be worrying about the starting year as much as you are - you
need to handle every leap year in the same fashion

So lets try something like this

leap_year = starting_year + starting_year % 4 #set yourself onto a possible
leap year to start with

while leap_year <= ending_year
  if (leap_year % 100) != 0 || (leap_year % 400) == 0
    puts leap_year
  end
  leap_year = leap_year + 4
end

And if for some reason you have a problem with the or statement ("||") you
can use this instead

if (leap_year % 100) != 0
  puts leap_year
elsif (leap_year % 400) == 0
  puts leap_year
end

John