My code compiles but the only functions that had no errors are the print_winner and eliminate functions. I have tried to solve the errors for the other functions with no luck.
My errors with the vote function are: ":( vote returns false when given name of invalid candidate,vote function did not return false", ":( vote correctly sets first preference for first voter, vote function did not correctly set preferences", and ":( vote correctly sets all preferences for voter, vote function did not correctly set preferences".
For my tabulate function: ":( tabulate counts votes when all candidates remain in election, tabulate function did not produce correct vote totals", ":( tabulate counts votes when one candidate is eliminated, tabulate function did not produce correct vote totals", and ":( tabulate counts votes when multiple candidates are eliminated, tabulate function did not produce correct vote totals".
For my find_min function: ":( find_min returns minimum number of votes for candidate, find_min did not identify correct minimum", and ":( find_min returns minimum when all candidates are tied, find_min did not identify correct minimum".
Lasltly, my is_tie function: ":( is_tie detects tie after some candidates have been eliminated, is_tie did not return true".
**
bool vote(int voter, int rank, string name)
{
// iterates over candidates to see if name matches the name provided for ranking and if so records the preference
for (int i = 0; i < candidate_count; i++)
{
if (strcmp(name, candidates[i].name) == 0)
{
preferences[voter][rank] = i;
return true;
}
}
return false;
}
// Tabulate votes for non-eliminated candidates
void tabulate(void)
{
// TODO
int j = 0;
for (int i = 0; i < voter_count; i++)
{
if (candidates[i].eliminated == false)
{
candidates[i].votes++;
}
else if (candidates[i].eliminated == true)
{
j++;
}
}
return;
}
// Print the winner of the election, if there is one
bool print_winner(void)
{
// TODO
for (int i = 0; i < candidate_count; i++)
{
if (candidates[i].votes > voter_count / 2 + 0.5)
{
printf(" %s\n", candidates[i].name);
return true;
}
}
return false;
}
// Return the minimum number of votes any remaining candidate has
int find_min(void)
{
// TODO
int lowVote = candidates[0].votes;
for (int i = 0; i < candidate_count; i++)
{
if (candidates[i].eliminated == false && candidates[i].votes < lowVote)
{
lowVote = candidates[i].votes;
return lowVote;
}
}
return 0;
}
// Return true if the election is tied between all candidates, false otherwise
bool is_tie(int min)
{
// TODO
int tiecount = 0;
for (int i = 0; i < candidate_count; i++)
{
if (candidates[i].votes == min)
{
tiecount++;
}
if (candidates[i].eliminated == false && tiecount == candidate_count)
{
return true;
}
}
return false;
}
// Eliminate the candidate (or candidiates) in last place
void eliminate(int min)
{
// TODO
for (int i = 0; i < candidate_count; i++)
{
if (candidates[i].eliminated == false && candidates[i].votes == min)
{
candidates[i].eliminated = true;
}
}
return;
}
**
Any help would be greatly appreciated!