0

I am relatively new to the community so please forgive me should my question not be coherent enough.

Ok so basically check 50 tells me that everything in my code is okay except for the locked pairs function whereby it is unable to lock cycles. My logic in the code is that, before locking, I would scan the previous locks to see if the current winner which I am about to lock, had lost in any of the previous pairs already locked in. If it doesn't the loop would continue and lock as per normal.Below is my code:

void lock_pairs(void)
{

    for (int i = 0; i < candidate_count; i++)
    {
        for (int j = 0; j <candidate_count; j++)
        {
            if (i == j)
            {
                locked[i][j] = false;
            }
        }
    }
    
    for (int u = 0;u < pair_count; u++)
    {
        for (int i = 0;i < u ; i++)
        {
            if (pairs[u].winner == pairs[i].loser)
            {
                locked[pairs[u].winner][pairs[u].loser] = false;
                continue;
            }
            
        }
        locked[pairs[u].winner][pairs[u].loser] = true;
        locked[pairs[u].loser][pairs[u].winner] = false;
        
       
    }
    
    
    return;
}

This is what check50 prompts me:

:) 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
    lock_pairs did not correctly lock all non-cyclical pairs

I get the feeling that something is really wrong in my code, but I just can't place my finger on it. Can someone please help in explaining what went wrong in this function in particular?

You must log in to answer this question.

Browse other questions tagged .