Console.WriteLine ("Please start voting for five students (0/1/2/3/4):");
int[] vote = new int[5];//vote for five people, define an array of length 5, each subscript represents a person
for (int i = 0; i < i++)//30 vote, one vote per person, Cycle 30 times
{
Number of votes in
Console.WriteLine ("Please" + (i + 1) + "peer vote (0,1,2,3,4):");//subscript starting from 0, vote for five people
int t = Convert.ToInt32 (Console.ReadLine ());
if (T < 0 | | T > 4)
{
Console.WriteLine ("Invalidated please re-cast");
continue;//invalidated included
}
Else
{
vote[t]++;
The number of votes cast
}
}
Calculate the final ticket
int max = 0, maxsub = 0;//defines an initial value of 0,max to get the highest ticket,//maxsub record the maximum worth subscript
for (int i = 0; i < 5; i++)
{
Show the number of votes for everyone.
Console.WriteLine ("+ vote[i" + "ticket" for candidates with "+ (i) +");
if (Vote[i] > Max)//Calculate the maximum value
{
max = Vote[i];
Maxsub = The subscript position of the i;//maximum value
}
}//Show Final Results
Console.WriteLine ("Final poll Result:" + maxsub + "elected with" + Max + "ticket);
}
Console.ReadLine ();
}
Example: 30 people voted for squad leader. The main learning array, the array is also more difficult to learn, as a reference question