Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5

Halp again. C woes... >_>
#1

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

[Image: signature.jpg]
Reply
#2

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
}
Reply
#3

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

[Image: signature.jpg]
Reply
#4

I <3 you.

[Image: signature.jpg]
Reply
#5

You're welcome.
Reply
#6

MTGO

[Image: versedforum.gif]
Reply
#7

wut

[Image: signature.jpg]
Reply
#8

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

[Image: wiekszx6.jpg]
Reply
#9

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

[Image: signature.jpg]
Reply
#10

jwstohr Wrote:the other 174 lines I wrote myself.

Yay! :lol:
Reply


Forum Jump:


Users browsing this thread: 1 Guest(s)