Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Feb 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Please suggest newbie forum

    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!
    Last edited by DayOne; 02-12-2009 at 02:53 PM.

  • #2
    New Coder
    Join Date
    Feb 2009
    Posts
    30
    Thanks
    1
    Thanked 7 Times in 7 Posts
    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.
    Last edited by CodeSpawn; 02-12-2009 at 04:29 PM.

  • #3
    New to the CF scene
    Join Date
    Feb 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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
    Last edited by DayOne; 02-13-2009 at 01:45 AM.

  • #4
    New Coder
    Join Date
    Feb 2009
    Posts
    30
    Thanks
    1
    Thanked 7 Times in 7 Posts
    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.
    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
    end
    to
    $end
    And it works perfectly. Nice code BTW.

  • #5
    New to the CF scene
    Join Date
    Feb 2009
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Thumbs up

    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.

  • #6
    New Coder
    Join Date
    Feb 2009
    Posts
    30
    Thanks
    1
    Thanked 7 Times in 7 Posts
    I'm glad that it is working for you. Good luck learning Ruby.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •