find matches issue

Hello there...The rest of my code is working fine so I'll try not to bother you with the whole thing. If the lottery or user numbers have multiples of the same number the match counts it as another match. My question is how do I make my findMatches function only count one match? ie user 2 0 0 0 0 compared to lottery 3 2 2 5 2 = 1 match.....
1
2
3
4
5
6
7
8
9
10
11
int findMatches(int lottery[], int user[], int size)
{
	int numMatches = 0;
	for (int choice = 0; choice < ARRAY_SIZE; ++choice)
		{	for (int i = 0; i < ARRAY_SIZE; i++)
				if (user[choice] == lottery[i])
					numMatches++;
		}	
				return numMatches;

}

example:: matched 3 different numbers
Enter five numbers 0 through 9 for lottery numbers
Enter Number1: 6
Enter Number2: 1
Enter Number3: 4
Enter Number4: 0
Enter Number5: 0
Your numbers:
6 1 4 0 0
Lottery numbers:
6 1 4 8 9
You matched 3 numbers.
Press any key to continue . . .

example:: matched 1 number to 3 of same type
Enter five numbers 0 through 9 for lottery numbers
Enter Number1: 2
Enter Number2: 0
Enter Number3: 0
Enter Number4: 0
Enter Number5: 0
Your numbers:
2 0 0 0 0
Lottery numbers:
3 2 2 5 2
You matched 3 numbers.
Press any key to continue . . .

Anyone have a hint?
closed account (zb0S216C)
Would this work for you (modify this at your own will):

1
2
3
4
5
6
7
8
9
10
11
12
13
int findMatches( int( &LotteryNums )[5], int( &UserNums )[5] )
{
    int ValidNumbers( 0 );
 
    for( int i( 0 ); i < 5; i++ )
    {
        for( int J( 0 ); J < 5; J++ )
            if( UserNums[i] == LotteryNums[J] )
                ValidNumbers++;
    }

    return ValidNumbers;
}

[Note: I've modified this code]

Wazzak
Last edited on
closed account (DSLq5Di1)
1
2
3
4
5
if (user[choice] == lottery[i])
{
    numMatches++;
    break;
}
closed account (zb0S216C)
Sloppy, take a closer look at your code. What do you notice?

Wazzak
closed account (DSLq5Di1)
I notice another problem, though I see one with your solution too hehe.
closed account (zb0S216C)
What's wrong with mine?

Wazzak
closed account (DSLq5Di1)
Your edit is making progress, but now it also mirrors the OP's original code and problem..

1
2
3
4
5
6
7
...
        if (user[choice] == lottery[i])
        {
            numMatches++;
            lottery[i] = -1 // invalidate this lottery number from any further matches
            break;
        }
Topic archived. No new replies allowed.