Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // Record pairs of candidates where one is preferred over the other
- void add_pairs(void)
- {
- pair_count = candidate_count * (candidate_count - 1) / 2; //calculate number all pairs
- int ties = 0;
- for (int i = 0; i < pair_count; i++)
- {
- for (int j = 0; j < pair_count; j++)
- {
- if(preferences[i][j] == preferences[j][i]) // if tie, tie++
- {
- ties++;
- }
- else if(preferences[i][j] > preferences[j][i]) // this adds to pairs array
- {
- pairs[i].winner = i;
- pairs[i].loser = j;
- }
- else // this too
- {
- pairs[i].winner = j;
- pairs[i].loser = i;
- }
- }
- }
- printf("ties: %i", ties); // check50 shows mistake without that line and i dont get it
- /* the mistake:
- :( add_pairs generates correct pair count when no ties
- add_pairs function did not produce 3 pairs
- */
- pair_count = pair_count - ties; // subtract number of ties from pairs to get number of valid pairs
- return;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement