Skip to main content
added 1523 characters in body
Source Link

// Query for votes for (int i = 0; i < voter_count; i++) { // ranks[i] is voter's ith preference int ranks[candidate_count];

    // Query for each rank
    for (int j = 0; j < candidate_count; j++)
    {
        string name = get_string("Rank %i: ", j + 1);

        if (!vote(j, name, ranks[j]))
        {
            printf("Invalid vote.\n");
            return 3;
        }
        else
        {
        ranks[j] = save;

        //Record_preferences should start here.
        for(int k = 0; k < candidate_count; k++)
        {
        int c = j;

        if(ranks[j] == k)
        {

            continue;
        }
        if(j > 0)
        {
            while(c > 0)
                {

                    if(k == ranks[c-1])
                    {
                        --c;

                        goto next;
                    }

                    --c;

                }
            ++preferences[ranks[j]][k];

            next:
            continue;
        }

        else
        {
            ++preferences[ranks[j]][k];

        }
        }
           //I commented out the record_preferences() function. 
           //record_preferences();
        }
    }

    printf("\n");
}

add_pairs();
sort_pairs();
lock_pairs();
print_winner();
return 0;

}

// Query for votes for (int i = 0; i < voter_count; i++) { // ranks[i] is voter's ith preference int ranks[candidate_count];

    // Query for each rank
    for (int j = 0; j < candidate_count; j++)
    {
        string name = get_string("Rank %i: ", j + 1);

        if (!vote(j, name, ranks[j]))
        {
            printf("Invalid vote.\n");
            return 3;
        }
        else
        {
        ranks[j] = save;

        //Record_preferences should start here.
        for(int k = 0; k < candidate_count; k++)
        {
        int c = j;

        if(ranks[j] == k)
        {

            continue;
        }
        if(j > 0)
        {
            while(c > 0)
                {

                    if(k == ranks[c-1])
                    {
                        --c;

                        goto next;
                    }

                    --c;

                }
            ++preferences[ranks[j]][k];

            next:
            continue;
        }

        else
        {
            ++preferences[ranks[j]][k];

        }
        }
           //I commented out the record_preferences() function. 
           //record_preferences();
        }
    }

    printf("\n");
}

add_pairs();
sort_pairs();
lock_pairs();
print_winner();
return 0;

}

added 2 characters in body
Source Link

I've created a solution to week 3's tideman problem which is entirely logically correct. Unfortunately, I had to dodge the standard solution by commenting out parts of a function and altering its parameters, so my solution cannot be accepted by check50.

The problem i'm facing is using arrays in functions.

C implicitly converts arrays when they are used as parameters in functions, so how am I supposed to code with a function such as "int record_preferences(int ranks[])".

What does ranks[] even mean? An array? An element of the array?

I altered the parameters once to "int record_preferences(int k, int ranks[k])" and called it with "record_preferences(j, ranks[j])" so I could actually use an element of the array, but that produced errors.

Before anyone mentions pointers - they are only taught in week 4 - I believe this problem should be solvable without problemspointers .

I've created a solution to week 3's tideman problem which is entirely logically correct. Unfortunately, I had to dodge the standard solution by commenting out parts of a function and altering its parameters, so my solution cannot be accepted by check50.

The problem i'm facing is using arrays in functions.

C implicitly converts arrays when they are used as parameters in functions, so how am I supposed to code with a function such as "int record_preferences(int ranks[])".

What does ranks[] even mean? An array? An element of the array?

I altered the parameters once to "int record_preferences(int k, int ranks[k])" and called it with "record_preferences(j, ranks[j])" so I could actually use an element of the array, but that produced errors.

Before anyone mentions pointers - they are only taught in week 4 - I believe this problem should be solvable without problems.

I've created a solution to week 3's tideman problem which is entirely logically correct. Unfortunately, I had to dodge the standard solution by commenting out parts of a function and altering its parameters, so my solution cannot be accepted by check50.

The problem i'm facing is using arrays in functions.

C implicitly converts arrays when they are used as parameters in functions, so how am I supposed to code with a function such as "int record_preferences(int ranks[])".

What does ranks[] even mean? An array? An element of the array?

I altered the parameters once to "int record_preferences(int k, int ranks[k])" and called it with "record_preferences(j, ranks[j])" so I could actually use an element of the array, but that produced errors.

Before anyone mentions pointers - they are only taught in week 4 - I believe this problem should be solvable without pointers .

Source Link

Passing arrays into function in tideman

I've created a solution to week 3's tideman problem which is entirely logically correct. Unfortunately, I had to dodge the standard solution by commenting out parts of a function and altering its parameters, so my solution cannot be accepted by check50.

The problem i'm facing is using arrays in functions.

C implicitly converts arrays when they are used as parameters in functions, so how am I supposed to code with a function such as "int record_preferences(int ranks[])".

What does ranks[] even mean? An array? An element of the array?

I altered the parameters once to "int record_preferences(int k, int ranks[k])" and called it with "record_preferences(j, ranks[j])" so I could actually use an element of the array, but that produced errors.

Before anyone mentions pointers - they are only taught in week 4 - I believe this problem should be solvable without problems.