A total of 20 students in each class, vote for the monitor, a total of 5 candidates, to achieve the vote, and calculate the most votes the person and his number of votes
int[] TP =New int[ -];//everybody vote. int[] PS =New int[5];//the number of votes received by each person//vote for(inti =0; I < TP. Length; i++) {Console.WriteLine ("Support number Please press 1, support second, press 2, support third, press 3, support fourth, press 4, support fifth please press 5"); Tp[i]=Convert.ToInt32 (Console.ReadLine ()); } //find out how many votes each candidate has received for(intj =0; J < TP. Length; J + +) { if(Tp[j] = =1)//If you vote 1, the first student adds a ticket.{ps[0] = ps[0] +1; } Else if(Tp[j] = =2)//vote 2 and the second student adds a ticket.{ps[1] = ps[1] +1; } Else if(Tp[j] = =3) {ps[2] = ps[2] +1; } Else if(Tp[j] = =4) {ps[3] = ps[3] +1; } Else if(Tp[j] = =5) {ps[4] = ps[4] +1; } } //See who has the most votes intmax = ps[0];//find the biggest for(intx =1; X < PS. Length; X + +) { if(Max <Ps[x]) {Max=Ps[x]; } } //OutputConsole.WriteLine ("the maximum number of votes received is:"+max); Console.Write ("the person with the highest number of votes:"); for(inty =0; Y < PS. Length; y++) { if(Ps[y] = =max) {Console.Write (y+1+","); }} console.readline ();
15-07-08 Array-voting for squad leader