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?
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
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.
Halp again. C woes... >_> -
insomniaprincess - Feb 28, 2009
jwstohr Wrote:the other 174 lines I wrote myself.
Yay! :lol: