• 02-12-2009, 02:30 PM
DayOne
Hi

I just started learning programming with a web tutorial here:

http://pine.fm/LearnToProgram/?Chapter=00

It's great but I one of the assignments (the Leap Years program at the end of chapter six) was too difficult and my code produces an endless loop!

It's a very simple program and I am very new to this so I didn't want to post it here where everyone seems to be "on rails" so to speak. Does anyone know a forum which is dedicated to helping beginners where I could maybe post my code and ask people to tell me where I 've gone wrong?

Thanks!
• 02-12-2009, 04:20 PM
CodeSpawn
I think You Can Use This Place For That.
But I just created my own forum. http://www.allcodeforum.co.nr I am trying to get more members so yea. It is dedicated to helping everyone in every programming language. I am good at most languages including ruby so I could help you. But I do want more members though.
• 02-13-2009, 01:42 AM
DayOne
Thanks, CodeSpawn. This place seemed too advanced for my question but I'll post my code here and see if anyone can help.
BTW, at the moment I wouldn't know where to post Ruby questions on your forum.

Here's my broken code anyway:

Code:

```puts 'This program calculates leap years between 2 dates' startyear = 0 endyear = 0 puts 'Enter start year:' startyear = gets.chomp if (startyear.to_i <= 0)   puts 'Your start year must be 1 AD or later!'   puts 'Re-enter start year:'   startyear = gets.chomp   end  puts 'Enter end year' endyear = gets.chomp if (endyear.to_i <= startyear.to_i)    puts 'Your end year must be later!'   puts 'Re-enter end year'   endyear = gets.chomp   end puts 'So that\'s leap years between ' + startyear + ' and ' + endyear + '?' puts 'OK, cool.' countstart = startyear.to_i countend = endyear.to_i # check if its a leap year. Leap years are years divisible by four # unless divisible by 100 # unless they are divisible by 400   while countstart <= countend # check if its a leap year     if (countstart % 4 != 0) or ((countstart % 100 == 0) and (countstart % 400 != 0))       puts countstart.to_s + ' is not a leap year'         else     puts countstart     end     countstart = countstart += 1       end   puts 'that is all' end```
• 02-13-2009, 05:43 PM
CodeSpawn
That is simple. First Of I forgot I just added Ruby to COMPUTER PROGRAMMING LANGUAGES. Lol I comleatly forgot about Ruby. It is still a new forum. So all the programming languages in the world can't be there from the beggining. But I am working on it.

As for you problem. I see only 2 things wrong with it. The code that calculates the leap years isn't bad. But I must admit it is annoying to see all the years and it saying is not a leap year.

So I would just take out this entire line.
Quote:

puts countstart.to_s + ' is not a leap year'
Other then that. It seems to work. The reason why it might not work for you is because at first the compiler whined to me. Something about unexpected kEND expected \$end. So I replaced the last line of your code from
Quote:

end
to
Quote:

\$end
And it works perfectly. Nice code BTW.
• 02-14-2009, 11:10 AM
DayOne
Thanks very much!!!! It works! I don't think I could have figured that out by myself.

The "(Year) is not a leap year" is totally annoying. You're right. It wasn't in my original code.When it didn't work, I added that line to see what was happening to the loop when the program was running. I'll take it out again so I don't annoy myself!

Good luck with your forum. I am gonna have some more Ruby questions in the future, for sure.

Thanks again.
• 02-15-2009, 06:48 PM
CodeSpawn
I'm glad that it is working for you. Good luck learning Ruby.