Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Windows Form C# Write an app to simulate the rolling of two dice. The app should

ID: 3721424 • Letter: W

Question

Windows Form C#

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

Below is your code.. Please let me know in comments if you have any issues

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

//namespace to hold the program
namespace TestConsole
{
//class to run the program
class Program
{
//main method to run the program
static void Main(string[] args)
{
//declaring array
int[] arr = new int[13]{0,0,0,0,0,0,0,0,0,0,0,0,0};
//variables to hold random numbers
int randomNum1,randomNum2;
//Random number initialization
Random rand = new Random();
//loop to be executed 36000 times
for (int i = 0; i < 36000; i++)
{
//generating the numbers and incrementing count of sum
randomNum1=rand.Next(1,7);
randomNum2 = rand.Next(1, 7);
arr[(randomNum1+randomNum2)]++;
}
//Output of information
Console.WriteLine("OUTPUT:");
Console.WriteLine("Sum Count");
for (int i = 2; i <arr.Length; i++)
Console.WriteLine("{0} {1}",i,arr[i]);
  
}
}
}

Output

Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
Chat Now And Get Quote