Create a dice simulator in C#. Comment code to explain what is the functions are doing. The simulator must roll the dice 6 times and it must add the 3 highest roll values. So, say it simulates: 4 4 3 2 1 5 after rolling six times. The total would be 13 (4+4+5=13). 4,4,5, are the largest numbers out of the 6 values. Add the three largest numbers together. Repeat this 6 different times.
If the random dice simulator simulates the outcomes below it should output: 13, 13, 15, 12, 16, 12.
1) 4 4 3 2 1 5
2) 2 3 6 1 3 4
3) 5 3 1 4 6 2
4) 4 2 2 1 1 6
5) 5 4 5 6 3 1
6) 1 2 4 5 3 2
//c# program
using System.IO;
using System;
class Program
{ //function to generate random number
public static int RandomNumber(int min, int max)
{
Random random = new Random();
return random.Next(min, max);
}
//main driver function
static void Main()
{
int first=0,second=0,third=0;
int sum=0;
for(int i=0;i<6;i++){
first=0;second=0;third=0;
for(int j=0;j<6;j++){
int num = RandomNumber(1, 6) ;
if (num > first)
{
third = second;
second = first;
first = num;
}
else if (num > second)
{
third = second;
second = num;
}
else if (num > third)
third = num;
}
sum = first+second+third;
Console.WriteLine(sum);
}
}
}
Create a dice simulator in C#. Comment code to explain what is the functions are doing....