Skip to content

Instantly share code, notes, and snippets.

@zastrow
Last active December 11, 2015 02:09
Show Gist options
  • Save zastrow/4528502 to your computer and use it in GitHub Desktop.
Save zastrow/4528502 to your computer and use it in GitHub Desktop.
Exercise from "Learning to Program" Chapter 7: Leap Year Generator. Insert two different years and the program will calculate all the leap year(s) between them.
while true
puts 'Start Year:'
yearOne = gets.chomp.to_i
puts 'End Year:'
yearTwo = gets.chomp.to_i
if yearOne > yearTwo
startYear = yearTwo
endYear = yearOne
else
startYear = yearOne
endYear = yearTwo
end
if ((endYear - startYear) <= 4)
puts ''
puts 'ERROR!'
puts '-----------------------------------------'
puts 'Years need to be more than 4 years apart.'
puts 'Please try again.'
puts '-----------------------------------------'
puts ''
else
puts ''
puts 'Displaying leap years between ' + startYear.to_s + '-' + endYear.to_s + '.'
while startYear <= endYear
startYear = startYear + 1
if startYear % 4 == 0 && ( startYear % 100 != 0 || startYear % 400 == 0 )
puts startYear
end
end
break
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment