In C# with screenshot of the output. Write an app to simulate the rolling of two
ID: 3718489 • Letter: I
Question
In C# with screenshot of the output.
Write an app to simulate the rolling of two dice. The app should use an object of class Random once to roll the first die and again to roll the second die. The sum of the two values should then be calculated. Each die can show an integer value from 1 to 6, so the sum of the values will vary from 2 to 12, with 7 being the most frequent sum and 2 and 12 the least frequent sums. Your application should roll the dice 36000 times. Use a one- dimensional array to tally the number of times each possible sum appears. Display the results in tabular format.
Explanation / Answer
using System.IO;
using System;
class Program
{
static void Main()
{
int[] roll = new int[11];
Random r = new Random();
for(int i=0;i<36000;i++) {
int r1= r.Next(1, 7);
int r2= r.Next(1, 7);
roll[r1+r2-2]++;
}
for(int i=0;i<roll.Length;i++) {
Console.WriteLine((i+2)+": "+roll[i]);
}
}
}
Output: