Thread: do while loop keeps looping

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Jun 2009
    Posts
    53
    Quote Originally Posted by laserlight View Post
    Suppose number2 has the value of 10. On the first iteration of the loop,
    removed = number2 / 20 = 10 / 10 = 1.
    digit = removed % 10 = 1 % 10 = 1
    ...
    digit != '\0' = 1 != 0 = 1
    so we go on to the next iteration. In the next iteration,
    removed = number2 / 20 = 10 / 10 = 1.
    digit = removed % 10 = 1 % 10 = 1
    At this point we can easily conclude that since number2 is never changed, the loop will loop infinitely.
    Ah I see. That was really stupid of me. So basically I need to give number2 the removed value so it keeps going down by 1 digit each time. Let me give this a shot, thanks laserlight

  2. #2
    Registered User
    Join Date
    Jun 2009
    Posts
    53
    Quote Originally Posted by wankel View Post
    Ah I see. That was really stupid of me. So basically I need to give number2 the removed value so it keeps going down by 1 digit each time. Let me give this a shot, thanks laserlight
    Got it working. I just used this:

    Code:
    number2 = number2/10;
    etc
    Everything is working awesome, only problem is that i get a zero at the end. for example:
    1
    x 1234
    --------
    4
    3
    2
    1
    0

    Would there be a more efficient way to loop this so that I dont always get a zero at the end?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 8
    Last Post: 12-01-2008, 10:09 AM
  2. return to start coding?
    By talnoy in forum C++ Programming
    Replies: 1
    Last Post: 01-26-2006, 03:48 AM
  3. loop needed also how to make input use letters
    By LoRdHSV1991 in forum C Programming
    Replies: 3
    Last Post: 01-13-2006, 05:39 AM
  4. when a while loop will stop ?
    By blue_gene in forum C Programming
    Replies: 13
    Last Post: 04-20-2004, 03:45 PM
  5. How to change recursive loop to non recursive loop
    By ooosawaddee3 in forum C Programming
    Replies: 1
    Last Post: 06-24-2002, 08:15 AM