Thread: do while loop keeps looping

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    '\0' is an int. Character literals in C are ints.

  2. #2
    Registered User
    Join Date
    Jun 2009
    Posts
    53
    Hi, Im experiencing a slight issue, this maybe what you guys were discussing. The loop works nicely except that when two zeros are multiplied the loop breaks. Is "digit != '\0'" not the correct condition for this?

  3. #3
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,336
    Quote Originally Posted by wankel View Post
    Hi, Im experiencing a slight issue, this maybe what you guys were discussing. The loop works nicely except that when two zeros are multiplied the loop breaks. Is "digit != '\0'" not the correct condition for this?
    Well, it's the right condition for "stop when the product is 0". As you noticed, that doesn't necessarily mean you're done with the problem. You need to stop when the number you're multiplying by has been reduced to 0.

  4. #4
    Registered User
    Join Date
    Jun 2009
    Posts
    53
    Quote Originally Posted by tabstop View Post
    Well, it's the right condition for "stop when the product is 0". As you noticed, that doesn't necessarily mean you're done with the problem. You need to stop when the number you're multiplying by has been reduced to 0.
    that makes a lot of sense, so I changed it from "digit" to "number2", but nothings changed?

    example:

    101
    x101
    -----
    101
    -----
    10201


    when its supposed to be:

    101
    x101
    ------
    101
    10100
    ------
    10201

    edit: nevermind, im so dumb. got it solved.

    Last question, im having it display the product only if its not the final answer or a zero, so I have this condition:

    if (product != final_product || product != 0)
    {
    print product
    }

    however, only the first part of that condition works. zeros are still displayed. Is the formatting wrong? Im not getting any errors when im compiling it
    Last edited by wankel; 06-15-2009 at 04:44 PM.

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