using System; /// Votes.cs implements vote counting. public class Votes { public static void Main() { int[] votes = {0, 0, 0, 0}; // holds votes for 4 candidates //int[] votes = new int[4]; // each cell starts with 0 bool processing = true; // collect the votes: while ( processing ) { Console.Write("Type your vote (0,1,2,3): "); int v = Int32.Parse(Console.ReadLine()); if ((v < 0) || (v > 3)) { processing = false; } // bad vote, so quit else { votes[v] = votes[v] + 1; } } // print the totals: for ( int i = 0; i != votes.Length; i = i + 1 ) { Console.WriteLine("Candidate " + i + " has " + votes[i] + " votes"); } Console.ReadLine(); } }