Posts: 560
	Threads: 11
	Joined: Sep 30, 2008
	
		
	
 
	
	
		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? 
	 
	
	
	
	
	
 
 
	
	
	
		
	Posts: 5,877
	Threads: 182
	Joined: Dec 11, 2004
	
		
	
 
	
	
		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
}
 
	 
	
	
	
	
	
 
 
	
	
	
		
	Posts: 560
	Threads: 11
	Joined: Sep 30, 2008
	
		
	
 
	
	
		that would all go into a loop function as well though, right? Looks like it should work. Will give it a shot 
	 
	
	
	
	
	
 
 
	
	
	
		
	Posts: 560
	Threads: 11
	Joined: Sep 30, 2008
	
		
	
 
 
	
	
	
		
	Posts: 5,877
	Threads: 182
	Joined: Dec 11, 2004
	
		
	
 
 
	
	
	
		
	Posts: 729
	Threads: 69
	Joined: May 06, 2008
	
		
	
 
 
	
	
	
		
	Posts: 560
	Threads: 11
	Joined: Sep 30, 2008
	
		
	
 
 
	
	
	
		
	Posts: 63
	Threads: 1
	Joined: Feb 24, 2008
	
		
	
 
	
	
		wow way to go stohr... take credit for someone else's work
	
	
	
	
	
	
 
 
	
	
	
		
	Posts: 560
	Threads: 11
	Joined: Sep 30, 2008
	
		
	
 
	
	
		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. 
	 
	
	
	
	
	
 
 
	
	
	
		
	Posts: 804
	Threads: 24
	Joined: Aug 17, 2008
	
		
	
 
	
	
		jwstohr Wrote:the other 174 lines I wrote myself.
Yay!  :lol: