/** * Determines which candidate has to be cut from the current round **/ private void CutCand(int cut) { for (int i = 0; i < VotingRoll.Count; i++) { Vote Current = VotingRoll.ElementAt(i); if (Current.getValid()) { Current.dropcand(cut); } } CuttedCand.Add(cut); }
/** * Calculate the current round when the button COUNT is pressed. * Takes no parameters as it uses the Vote object that is stored when importing. **/ private int cal()// Did some one win, who cuts { barChartToolStripMenuItem.Enabled = true; switch (cand.Length) { case 1: candidateController.candLabel1.Text = cand[0]; break; case 2: candidateController.candLabel2.Text = cand[1]; goto case 1; case 3: candidateController.candLabel3.Text = cand[2]; goto case 2; case 4: candidateController.candLabel4.Text = cand[3]; goto case 3; case 5: candidateController.candLabel5.Text = cand[4]; goto case 4; case 6: candidateController.candLabel6.Text = cand[5]; goto case 5; case 7: candidateController.candLabel7.Text = cand[6]; goto case 6; case 8: candidateController.candLabel8.Text = cand[7]; goto case 7; case 9: candidateController.candLabel9.Text = cand[8]; goto case 8; case 10: candidateController.candLabel10.Text = cand[9]; goto case 9; default: break; } int[] totalForCand = new int[cand.Length]; double[] percent = new double[cand.Length]; int totalVotes = VotingRoll.Count; //for each vote for (int i = 0; i < VotingRoll.Count; i++) { Vote Current = VotingRoll.ElementAt(i); if (Current.getValid()) { //Get the first vote for (int index = 0; index < Current.Votes.Length; index++) { if (Current.Votes[index] == 1) { totalForCand[index] += 1; } } } } switch (cand.Length) { case 1: candidateController.scoreLabel1.Text = totalForCand[0].ToString(); break; case 2: candidateController.scoreLabel2.Text = totalForCand[1].ToString(); goto case 1; case 3: candidateController.scoreLabel3.Text = totalForCand[2].ToString(); goto case 2; case 4: candidateController.scoreLabel4.Text = totalForCand[3].ToString(); goto case 3; case 5: candidateController.scoreLabel5.Text = totalForCand[4].ToString(); goto case 4; case 6: candidateController.scoreLabel6.Text = totalForCand[5].ToString(); goto case 5; case 7: candidateController.scoreLabel7.Text = totalForCand[6].ToString(); goto case 6; case 8: candidateController.scoreLabel8.Text = totalForCand[7].ToString(); goto case 7; case 9: candidateController.scoreLabel9.Text = totalForCand[8].ToString(); goto case 8; case 10: candidateController.scoreLabel10.Text = totalForCand[9].ToString(); goto case 9; default: break; } // for (int i = 0; i < totalForCand.Length; i++) { percent[i] = (totalForCand[i] * 100) / totalVotes; if (percent[i] > 50) { VotingOver = true; WinningCand = cand[i]; } } int lowest = totalForCand[0]; int lowIndex = 0; // cut people out if noone is a winner for (int i = 0; i < totalForCand.Length; i++) { if (totalForCand[i] < 0) { continue; } if (totalForCand[i] < lowest && !CuttedCand.Contains(i)) { lowest = totalForCand[i]; lowIndex = i; } // //Console.WriteLine("Candidate " + cand[i] + " has the total percentage of Votes of: " + percent[i] + "%"); } // results for round x String[] results = new string[cand.Length + 1]; // Round , score/ cut ++++ results[0] = rounds.Count.ToString(); for (int loop = 0; loop < cand.Length; loop++) { if (CuttedCand.Contains(loop) || loop == lowIndex) {//P if cut results[loop + 1] = "P"; } else { results[loop + 1] = totalForCand[loop].ToString(); } } rounds.Add(results); currentVotes = new int[cand.Length]; currentVotes = totalForCand; return(lowIndex); }