I would use use one for loop than to increment the rand[] than the single value to a function with the user array compare the rand in a for loop in different function and than return the counter if it evaluates as a match it will increment. It really the same as what your doing but your setting the counter to zero again on the nested for loop which won't work. I only separate the for loops as preference your way should work if you don't set the counter to zero again within the nested for loop.
int counter (int ran[],int user[])
{
int counter=0;
for (int i=0;i<5;++i)
{
int counter=0;
for (int j=0;j<5;++j)
{
if (ran[i] == user[j])
counter ++;
}
return counter;
}