repeat number program

This is a discussion on repeat number program within the C Programming forums, part of the General Programming Boards category; Can someone help me with how I can re-enter this loop after it breaks from the first repeated number? I ...

  1. #1
    Registered User
    Join Date
    Oct 2002
    Posts
    5

    repeat number program

    Can someone help me with how I can re-enter this loop after it breaks from the first repeated number? I need it to display all of the repeated numbers in the integer that the user enters.
    Code:
    #include <stdio.h>
    
    #define TRUE 1
    #define FALSE 0
    
    typedef int Bool;
    
    main(){
    
    Bool digit_seen[10] = {0};
    
    int digit;
    long int n;
    
    printf ("Enter a number: ");
    scanf("%ld", &n);
    
    while (n > 0){
     digit = n % 10;
     if (digit_seen[digit])
     break;
     digit_seen[digit] = TRUE;
     n /= 10;
    }
    
    if(n>0)
    printf("The repeated digit(s) are:%3d\n", digit);
    else
    printf("No Repeat");
    
    return 0;
    }
    Last edited by nicolobj; 10-03-2002 at 11:45 PM.

  2. #2
    Lead Moderator kermi3's Avatar
    Join Date
    Aug 1998
    Posts
    2,595
    I am posting this because you did not use code tags on this thread. In the furture please use Code Tags. They make your code MUCH easier to read and people will be much more likely to help you if you do. And they'll be happy about helping you


    For example:

    Without code tags:

    for(int i=0;i<5;i++)
    {
    cout << "No code tags are bad";
    }

    With Code Tags:
    Code:
    for(int i=0;i<5;i++)
    {
         cout << "This code is easy to read";
    }
    This is of course a basic example...more complicated code is even easier to read with code tags than without.

    I've added code tags for you this time. They can be added by putting [code] at the beginning of your code and [/code] at the end. More information on code tags may be found at the link in my signature. Any further questions or ways I can help please feel free to PM me.


    You were close....just use [] instead of <>.
    Kermi3

    If you're new to the boards, welcome and reading this will help you get started.
    Information on code tags may be found here

    - Sandlot is the highest form of sport.

  3. #3
    Lead Moderator kermi3's Avatar
    Join Date
    Aug 1998
    Posts
    2,595
    Ah you editted it before I could....very good . Here folks is someone who tries and is smart enough to look things up!
    Kermi3

    If you're new to the boards, welcome and reading this will help you get started.
    Information on code tags may be found here

    - Sandlot is the highest form of sport.

  4. #4
    Registered User
    Join Date
    Oct 2002
    Posts
    5
    Sorry about that, is there any chance that you could help me with this problem?

  5. #5
    Lead Moderator kermi3's Avatar
    Join Date
    Aug 1998
    Posts
    2,595
    umm i didn't look extremely closely...it's well past the time that i should be asleep so I'm a bit blury eyed but I would try a nested loop. That's when you put one loop inside another. So put an outer while loop that has conditions that make it so it repeats as much as you want....Hope this helps...I'm off to bed.

    Oh, and no prob on the code tags, happens all the time, and many people don't make the effort to do it at all on their first post, thanks.
    Kermi3

    If you're new to the boards, welcome and reading this will help you get started.
    Information on code tags may be found here

    - Sandlot is the highest form of sport.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Program Plan
    By Programmer_P in forum C++ Programming
    Replies: 0
    Last Post: 05-11-2009, 02:42 AM
  2. Need help getting program print out the digit in words
    By cosmiccomputing in forum C Programming
    Replies: 26
    Last Post: 04-24-2008, 09:28 AM
  3. Using variables in system()
    By Afro in forum C Programming
    Replies: 8
    Last Post: 07-03-2007, 01:27 PM
  4. Fibonacci number program problem(assembly)
    By ok_good in forum Tech Board
    Replies: 7
    Last Post: 04-07-2006, 08:27 PM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21