Results 1 to 10 of 10

Thread: Halp again. C woes... >_>

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    jwstohr's Avatar



    Join Date
    Sep 30, 2008
    Last Online
    Mar 06, 2011
    Posts
    560
    Threads
    11



    Halp again. C woes... >_>


    Ok this time it is a simple thing that I just cannot "get".

    I need to fill an array b[6] with random unique numbers 1-15. I can generate random numbers and everything just fine... I just cannot figure out a way to compare the generated number to the array already done to check if it is a duplicate. And of course if not a duplicate, put it in the array. Rinse and repeat.

    Any ideas?

  2. #2
    Drunken F00l's Avatar



    Join Date
    Dec 11, 2004
    Last Online
    Jun 11, 2019
    Posts
    5,874
    Threads
    182
    Reputation
    SourceOP Thread


        
    Steam: 76561197968459473 
    Steam join date: Aug 23, 2004
    Steam Level: 56
    Profile Status: Public



    Something like?:

    Code:
    int isDuplicate = 0;
    int newNumber = your_random_number_function();
    
    // check for duplicate
    for(int i = 0; i < 6; i++)
    {
        if(b[i] == newNumber)
        {
            isDuplicate = 1;
        }
    }
    
    if(!isDuplicate)
    {
        // add to array here
    }

  3. #3
    jwstohr's Avatar



    Join Date
    Sep 30, 2008
    Last Online
    Mar 06, 2011
    Posts
    560
    Threads
    11




    that would all go into a loop function as well though, right? Looks like it should work. Will give it a shot

  4. #4
    jwstohr's Avatar



    Join Date
    Sep 30, 2008
    Last Online
    Mar 06, 2011
    Posts
    560
    Threads
    11




    I <3 you.

  5. #5
    Drunken F00l's Avatar



    Join Date
    Dec 11, 2004
    Last Online
    Jun 11, 2019
    Posts
    5,874
    Threads
    182
    Reputation
    SourceOP Thread


        
    Steam: 76561197968459473 
    Steam join date: Aug 23, 2004
    Steam Level: 56
    Profile Status: Public



    You're welcome.

  6. #6
    Versed's Avatar



    Join Date
    May 06, 2008
    Last Online
    Jun 22, 2011
    Posts
    729
    Threads
    69




    MTGO

  7. #7
    jwstohr's Avatar



    Join Date
    Sep 30, 2008
    Last Online
    Mar 06, 2011
    Posts
    560
    Threads
    11




    wut

  8. #8
    wieks's Avatar



    Join Date
    Feb 24, 2008
    Last Online
    Feb 25, 2011
    Posts
    63
    Threads
    1




    wow way to go stohr... take credit for someone else's work

  9. #9
    jwstohr's Avatar



    Join Date
    Sep 30, 2008
    Last Online
    Mar 06, 2011
    Posts
    560
    Threads
    11




    Actually that was a small piece of the big program. The program had to print out a user specified number of bingo cards to a file. Yeah, my teacher is crazy. I was just stuck on that part, the other 174 lines I wrote myself. I think I am getting the hang of this. :P

  10. #10
    insomniaprincess's Avatar



    Join Date
    Aug 17, 2008
    Last Online
    Jul 14, 2014
    Posts
    804
    Threads
    24




    Quote Originally Posted by jwstohr
    the other 174 lines I wrote myself.
    Yay!

Tags for this Thread