1

So my min code works, except it ignores the eliminate function. Can someone please show me where my logic is wrong? Thanks.

int find_min(void)
{
int min = voter_count;

int h = 0;

for (int i = 0; i < candidate_count; i++)
{
    if (candidates[i].votes < voter_count)
    {
        h = candidates[i].votes;
    }
}

for (int i = 0; i < candidate_count; i++)
{
    if ((candidates[i].votes == h) && (candidates[i].eliminated == false))
    {
        return h;
    }
}

return 0;

}

1

So I got the answer. My problem was the candidates[i].eliminated == false. Very easy to see, I don't know how I missed it. The candidates[i].eliminated == false should go with the first if function. If the candidate is eliminated, why would you even need to add their value to h? It should just be excluded at the initial stage.

| improve this answer | |
  • this was quite helpful for me I'm also stuck here thanks man:) – FoundABetterName Oct 24 at 14:02

You must log in to answer this question.

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