Last active
December 11, 2015 02:09
-
-
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.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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