I need help C looping

Discussion in 'Programming' started by Magina™, Jun 1, 2009.

  1. #1
    Please help me in this this code needs to be loop. I did my part I faild to do so.


     
    Magina™, Jun 1, 2009 IP
  2. lonewolff

    lonewolff Member

    Messages:
    338
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    30
    #2
    Two immediate problems.

    Loop is never initialised so while (loop !=0 ) will give you random results.
    And the other problem... You will end up with an infinite loop as you dont ever increment of decrement variable loop. So, the result for loop!=0 is always going to be the same.

    Also, your logic could be cleaned up a bit too as you dont need a hundred if's and else if's to do the job in this case.

    Good luck :)
     
    lonewolff, Jun 1, 2009 IP
  3. taarzan

    taarzan Active Member

    Messages:
    240
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    53
    #3
    well my suggestions begins with that good programmin practice donot make use of if else ladder instead "switch" statement is preffered instead of multiple "if's" , secondly it is another good practice to use "do while" loop in unexpected termination cases like the one urs.
    I disagree with above lone wolf first statement in this case u dont say " loop " variable is initialized but it is convineint to say that it is never assigned a value also the input u took with " ans " variable is not used so omit the loop variable and make use of ans variable in while loop will solve ur problem and will work fine .
     
    taarzan, Jun 2, 2009 IP
  4. lonewolff

    lonewolff Member

    Messages:
    338
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    30
    #4
    Thats the same thing. :rolleyes:

    What do you feel that this loop will do if loop is 'convineintly never assigned a value' or 'convineintly' never decremented or 'convineintly' never incremented.

    I would say that the results would be 'inconvineint' and would result in a post thread asking for help. ;)
     
    lonewolff, Jun 2, 2009 IP
  5. taarzan

    taarzan Active Member

    Messages:
    240
    Likes Received:
    0
    Best Answers:
    0
    Trophy Points:
    53
    #5
    well lonewolf nothing personal man...................
     
    taarzan, Jun 3, 2009 IP
  6. lonewolff

    lonewolff Member

    Messages:
    338
    Likes Received:
    1
    Best Answers:
    0
    Trophy Points:
    30
    #6
    Not at all :)
     
    lonewolff, Jun 3, 2009 IP