PDA

View Full Version : Halp again. C woes... >_>



jwstohr
Feb 26, 2009, 12:13 PM
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? :D

Drunken F00l
Feb 26, 2009, 01:23 PM
Something like?:



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
}

jwstohr
Feb 26, 2009, 01:44 PM
that would all go into a loop function as well though, right? Looks like it should work. Will give it a shot :D

jwstohr
Feb 26, 2009, 02:00 PM
I <3 you.

Drunken F00l
Feb 26, 2009, 02:11 PM
You're welcome.

Versed
Feb 26, 2009, 06:14 PM
MTGO

jwstohr
Feb 26, 2009, 10:54 PM
wut

wieks
Feb 27, 2009, 09:26 PM
wow way to go stohr... take credit for someone else's work

jwstohr
Feb 28, 2009, 03:13 AM
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

insomniaprincess
Feb 28, 2009, 10:11 AM
the other 174 lines I wrote myself.

Yay! :lol: