Welcome to Working With Rails


Discussion Forums

Discuss all things Ruby on Rails with perhaps the web's most vibrant group of Ruby on Rails enthusiasts.
2 Posts
ruby problem

This snippet should be in a loop I guess:

(1979...2040).each do |year|

if year % 400 == 0 or (year % 4 == 0 and (year % 100 != 0))

puts year

end end

Forum Rating: 100
Sign In To Rate Post


Before I want to start RoR I first want to start learning Ruby. So I follow this online book : http://pine.fm/LearnToProgram/?Chapter=06

But Im stuck at the leap year problem.

This is the code so far:

print "Enter beginning year : " begin_year = gets.chomp year1 = begin_year.to_i print "Enter end year : " end_year = gets.chomp year2 = end_year.to_i while year1 <= year2

 if ((year1 % 4 == 0) and (year1 %100 !=0) and (year1%400 == 0)
     puts year1
 year1 = year1 + 1


But I do not see the leap years. I can enter the years and then the programm has no output. What did I do wrong ?


Last Edited by roelof at 02 Sep 17:44
2 Posts
Login to add your message