Hot answers tagged

2

You return prematurely. Simply finding a vote count smaller than the max is not enough. You need to keep going until you've looked at all the candidates, and then return the smallest vote count. // Return the minimum number of votes any remaining candidate has int find_min(void) { int minVote = MAX_VOTERS; for (int x = 0; x < candidate_count; x++) ...


1

"Is it implicit in the above code that if vote returns true then the vote function runs as normal and updates the preferences array?" Answer: No. The vote function runs and then the result is evaluated. If vote returns true, the function has already updated the preferences array (assuming, of course, it's been written correctly :)


1

The code is not counting the number of digits correctly. It's generating counts that are one less than the actual length. You can verify this by inserting printf("cc_length = %i\n",cc_length); after the length is calculated. This is the root cause of the seg fault. Here's how. The number of elements in the array int arr[cc_length]; are one less ...


Only top voted, non community-wiki answers of a minimum length are eligible