2

I'm in the midst of working on tideman, in the midst of it i decide to check for the add_pairs function but i realised check50 is throwing me red coloured texts, solely based on add_pairs. I debugged line by line but I still can't pinpoint where my mistake lies.

It's odd as i passed 2 out of 4 of the add_pairs check, enter image description here

add_pairs function:

void add_pairs(void)
{
    // TODO
    // Preferences integers of stringed candidates
    // Candidates string
    // pairs - struct -> int winner, loser
    // i & j -> based on candidates
    for (int i = 0; i < candidate_count; i++) {
        for (int j = i + 1; j < candidate_count; j++) {
            if (preferences[i][j] > preferences[j][i]) {
                pairs[pair_count].winner = i;
                pairs[pair_count].loser = j;
                pair_count++;
                break;
            }
            else if (preferences[i][j] < preferences[j][i]) {
                pairs[pair_count].winner = j;
                pairs[pair_count].loser = i;
                pair_count++;
                break;
            }
        }
    }

    printf("[add_pairs]\n");
    for (int i = 0; i < pair_count; i++) {
        printf("Winner: %i, ", pairs[i].winner);
        printf("Loser: %i\n", pairs[i].loser);
    }

    return;
}

Appreciate all the feedback.

1 Answer 1

3

I solved it after few hours. Damn.. Silly me.. I just had to remove the two break;s

void add_pairs(void)
{
    // TODO
    // Preferences integers of stringed candidates
    // Candidates string
    // pairs - struct -> int winner, loser
    // i & j -> based on candidates
    for (int i = 0; i < candidate_count; i++) {
        for (int j = i + 1; j < candidate_count; j++) {
            if (preferences[i][j] > preferences[j][i]) {
                pairs[pair_count].winner = i;
                pairs[pair_count].loser = j;
                pair_count++;
            }
            else if (preferences[i][j] < preferences[j][i]) {
                pairs[pair_count].winner = j;
                pairs[pair_count].loser = i;
                pair_count++;
            }
        }
    }

    // printf("[add_pairs]\n");
    // for (int i = 0; i < pair_count; i++) {
    //     printf("Winner: %i, ", pairs[i].winner);
    //     printf("Loser: %i\n", pairs[i].loser);
    // }

    return;
}

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .