How to show the winner?

• Question

• I wonder if anyone can help me with showing the winner of this ping pong tournament.

her is the cod

{
int Peter = 0;
int Daniel = 0;
int Kim = 0;
int Philip = 0;
int Arild = 0;
int Junas = 0;
int Hans = 0;
int Hugo = 0;
int Linus = 0;
int Simon = 0;
int Johan = 0;
int Sigurd = 0;
int Robert = 0;
int Karl = 0;
int Erik = 0;
int Martin = 0;
int Isac = 0;
int Isak = 0;
int Pakorn = 0;
int Nils = 0;

int[] tävlande = new int[20];
tävlande[0] = Peter;
tävlande[1] = Daniel;
tävlande[2] = Kim;
tävlande[3] = Philip;
tävlande[4] = Arild;
tävlande[5] = Junas;
tävlande[6] = Hans;
tävlande[7] = Hugo;
tävlande[8] = Linus;
tävlande[9] = Simon;
tävlande[10] = Johan;
tävlande[11] = Sigurd;
tävlande[12] = Robert;
tävlande[13] = Karl;
tävlande[14] = Erik;
tävlande[15] = Martin;
tävlande[16] = Isac;
tävlande[17] = Isak;
tävlande[18] = Pakorn;
tävlande[19] = Nils;

Console.WriteLine("\n De tävlande fick följande poäng: \n");
Random rnd = new Random();

for (int x = 0; x < 20; x++)
{
for (int i = 0; i < 20; i++)
{

int p = rnd.Next(3);

if (p == 0)
tävlande[x] += 20;
else if (p == 1)
tävlande[x] += 10;

}
Console.WriteLine(tävlande[x]);
}
int a = tävlande.Max();
Console.WriteLine("Vinnaren hadde: " + a + "p");
}

Thursday, November 2, 2017 5:44 PM

All replies

• Hi Dacke00,

>>I wonder if anyone can help me with showing the winner of this ping pong tournament.

What are your specific questions and logic? I modify your below, hoping to help you.

```         Dictionary<int, string> winnerlisdic = new Dictionary<int, string>();
winnerlisdic.Add(0, "Peter");
winnerlisdic.Add(1, "Daniel");
winnerlisdic.Add(2, "Kim");
winnerlisdic.Add(3, "Philip");
winnerlisdic.Add(4, "Arild");
winnerlisdic.Add(5, "Junas");
winnerlisdic.Add(6, "Hans");
winnerlisdic.Add(7, "Hugo");
winnerlisdic.Add(8, "Linus");
winnerlisdic.Add(9, "Simon");
winnerlisdic.Add(10, "Johan");
winnerlisdic.Add(11, "Sigurd");
winnerlisdic.Add(12, "Robert");
winnerlisdic.Add(13, "Karl");
winnerlisdic.Add(14, "Erik");
winnerlisdic.Add(15, "Martin");
winnerlisdic.Add(16, "Isac");
winnerlisdic.Add(17, "Isak");
winnerlisdic.Add(18, "Pakorn");
winnerlisdic.Add(19, "Nils");

int[] tävlande = new int[20] { 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 };

Console.WriteLine("\n De tävlande fick följande poäng: \n");
Random rnd = new Random();
for (int x = 0; x < 20; x++)
{
for (int i = 0; i < 20; i++)
{
int p = rnd.Next(3);
if (p == 0)
tävlande[x] += 20;
else if (p == 1)
tävlande[x] += 10;

}
Console.WriteLine(tävlande[x]);
}

var v = tävlande.Select((m, index) => new { index, m }).OrderByDescending(n => n.m).Take(1).ToList()[0];
var WinnerO = winnerlisdic.FirstOrDefault(q => q.Key == v.index).Value;
MessageBox.Show("Vinnaren hadde: " + WinnerO  + " !, Score: "+ v.m);```

If I have any misunderstanding, you can include all necessary code snippets for anyone else to be able to reproduce your issue from scratch along with a detailed description about the results including any exception messages.

Best Regards,

Yohann Lu

MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.

Friday, November 3, 2017 5:52 AM