SourceOP
Halp again. C woes... >_> - Printable Version

+- SourceOP (http://forums.sourceop.com)
+-- Forum: Half-Life 2 (http://forums.sourceop.com/Half-Life-2-forum)
+--- Forum: General Chat (http://forums.sourceop.com/General-Chat--24-forum)
+---- Forum: Coding (http://forums.sourceop.com/Coding-forum)
+---- Thread: Halp again. C woes... >_> (/Halp-again-C-woes-thread)



Halp again. C woes... >_> - jwstohr - Feb 26, 2009

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? Big Grin


Halp again. C woes... >_> - Drunken F00l - Feb 26, 2009

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
}



Halp again. C woes... >_> - jwstohr - Feb 26, 2009

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


Halp again. C woes... >_> - jwstohr - Feb 26, 2009

I <3 you.


Halp again. C woes... >_> - Drunken F00l - Feb 26, 2009

You're welcome.


Halp again. C woes... >_> - Versed - Feb 26, 2009

MTGO


Halp again. C woes... >_> - jwstohr - Feb 26, 2009

wut


Halp again. C woes... >_> - wieks - Feb 27, 2009

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


Halp again. C woes... >_> - jwstohr - Feb 28, 2009

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. Tongue


Halp again. C woes... >_> - insomniaprincess - Feb 28, 2009

jwstohr Wrote:the other 174 lines I wrote myself.

Yay! :lol: