0

I have some trouble with PSET3 2020 runoff:

in Specification:

Complete the implementation of runoff.c in such a way that it simulates a runoff election. You should complete the implementations of the vote, tabulate, print_winner, find_min, is_tie, and eliminate functions, and you should not modify anything else in plurality.c (and the inclusion of additional header files, if you’d like).

1) Seems that it's mean that I can't modify the main and the header ?

2) Can't change in plurality.c ? maybe mean in runoff.c?

Here the 2 main problems:

1) Because I can't modify the header, how can I use strcmp (hints ask for) without string.h ?

3) part of the main count the vote in an array:

...C

// Keep querying for votes
for (int i = 0; i < voter_count; i++)
{

    // Query for each rank
    for (int j = 0; j < candidate_count; j++) //## => here it's not the rank
    {
        string name = get_string("Rank %i: ", j + 1);

        // Record vote, unless it's invalid
        if (!vote(i, j, name))
        {
            printf("Invalid vote.\n");
            return 4;
        }
    }

    printf("\n");
}

...

I wish I could change the line for:

for (int j = 0; j < 3; j++) // each voters can vote 3 times

Do I have misunderstood something?

Thanks in adance,

PS: This is my first post on StackExchange, I hope I've done it well.

2

1) Because I can't modify the header, how can I use strcmp (hints ask for) without string.h ?

You can include string.h as per the spec:

(and the inclusion of additional header files, if you’d like).

(and yes, it looks like plurality.c is a typo and should read runoff.c)

You cannot change to this for (int j = 0; j < 3; j++) // each voters can vote 3 times because that would only work if there were always 3 candidates. But (distro) program allows up to 9 candidates. Each voter must rank all of the candidates on the slate.

| improve this answer | |
  • Ok thanks a lot. And thanks to Blauelf too. I thought it was only 3 votes per voters. Now it's clear: each voter have to sort all the candidates (by preference). I'm very impressed by the quick answers. – saquiel Jan 7 at 17:49
1

The file name would likely be a typo :)

It's ok to add header includes to runoff.c. I guess that sentence got refactored a bit, and the part in parentheses should be moved to the where-to-change part to be less confusing.

Each voter has candidate_count votes, for the example of three candidates, that's three votes. It's the order that matters. Interestingly, the case of a voter voting twice for the same candidate does not seem to have been considered, my solution might do funny things then.

You did reasonably well for your first question. Sadly, the code blocks here do not allow you to specify a language, all they do is look for four spaces in front of each line.

| improve this answer | |

You must log in to answer this question.

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