return 0; } When you run this feature, you'll see:
sort_pairs(); lock_pairs_verbose(); // MODIFIED VERSION with visualization cs50 tideman
=== TIE-BREAKING VISUALIZATION === Total pairs created: 6 --- BEFORE SORTING --- Pair 1: Alice vs Bob Alice got 5 votes Bob got 3 votes Margin: Alice wins by 2 votes return 0; } When you run this feature,
// Add this after calculating preferences printf("\n--- ELECTION RESULTS VISUALIZATION ---\n"); } When you run this feature
// Identify and highlight ties printf("\n--- TIE ANALYSIS ---\n"); bool has_ties = false; for (int i = 0; i < pair_count - 1; i++) { int margin_current = preferences[pairs[i].winner][pairs[i].loser] - preferences[pairs[i].loser][pairs[i].winner]; int margin_next = preferences[pairs[i + 1].winner][pairs[i + 1].loser] - preferences[pairs[i + 1].loser][pairs[i + 1].winner]; if (margin_current == margin_next) { if (!has_ties) { printf("\n⚠️ TIES DETECTED in ranking:\n"); has_ties = true; } printf(" Ranks %i and %i have equal victory margins\n", i + 1, i + 2); } }
// Optional: Display preference matrix printf("\nPreference Matrix:\n"); for (int i = 0; i < candidate_count; i++) { for (int j = 0; j < candidate_count; j++) { printf("%3i ", preferences[i][j]); } printf("\n"); }