Example: 30 people voted for squad leader. The main learning array, the array is also more difficult to learn, as a reference question

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.