lottery error

Hi guys,
I need help in solving the following problem below.
if I chose numbers 2 2 3 3 4 and the lottery chose 2 3 5 7 0, I get 4 matches. The program counts 2 and 3 twice but it should only count each one once. I need help to resolve this bug in my program.

Problem given:
Write a function to count the number of matches between the winning numbers and the players ticket. Only count repeating elements for once. For example, if the user array is {1, 2, 1, 3, 5} and the lottery is {3, 4, 9, 0, 1}, then there are only 2 (1 and 3) matches. The function must return the number of matches.
int matchCount(int lottery[], int user[], const int LENGTH);



program:

int matchCount(int lottery[], int user[], const int LENGTH){
int matches=0;
for(int i=0; i<LENGTH; i++){
for(int j=0; j<LENGTH; j++){
int match=lottery[i]-user[j];
switch(match){
case 0:
matches=matches++;
user[j]=10;
break;
default:
break;
}
}
}
return matches;
}
Last edited on
Topic archived. No new replies allowed.