# PSET3 -Tideman - lock_pairs

I'm doing tideman and I can't understand where is the problem: my code seems to be working but the test says that it does not.

I will share a bit of my code:

``````int count = 1

void lock_pairs(void)
{
int users[pair_count];

for (int k = 0; k < pair_count; k++)
{
users[k] = -1;
}
for (int i = 0; i < pair_count; i++)
{
if (check(i, users))
{
locked[pairs[i].winner][pairs[i].loser] = true;
}
}
}

bool check(int n, int users[])
{

bool check1 = true;
bool check2 = true;

for (int i = 0; i < count; i++)
{
if (pairs[n].winner == users[i])
{
check1 = false;
break;
}
else if (pairs[n].winner != users[i] && count - 1 < pair_count)
{
users[count - 1] = pairs[n].winner;
count++;
break;
}
}

for (int j = 0; j < count; j++)
{
if (pairs[n].loser == users[j])
{
check2 = false;
break;
}
else if (pairs[n].winner != users[j] && count - 1 < pair_count)
{
users[count - 1] = pairs[n].loser;
count++;
break;
}
}

if (check1 == false && check2 == false)
{
return false;
}
else
{
return true;
}
}
``````
``````The output of test:
:) lock_pairs locks all pairs when no cycles
:( lock_pairs skips final pair if it creates cycle
lock_pairs did not correctly lock all non-cyclical pairs
:) lock_pairs skips middle pair if it creates a cycle
``````

I would be so thankful for help.

• why did you set every value in users into -1?? – Ojou Nii Apr 5 '20 at 17:40