-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathProgram.cs
More file actions
61 lines (48 loc) · 1.84 KB
/
Copy pathProgram.cs
File metadata and controls
61 lines (48 loc) · 1.84 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
// See https://aka.ms/new-console-template for more information
// Ask user how many rolls they would like
// For the number of times they said:
// Generate 2 random numbers 1-6
// Add two numbers together
// Go update the counter of each number
// For each of the numbers
// Print the number
// Calculate the percentage of the times it was rolled
// Print one asterisk for each percent it was rolled
internal class Program
{
public static void Main(string[] args)
{
Console.WriteLine("Welcome to the dice throwing simulator!");
Console.Write("How many dice rolls would you like to simulate? ");
int numberOfRolls = int.Parse(Console.ReadLine());
// array to count the number of times each number is rolled
int[] rollCounts = new int[13];
for (int i = 0; i < numberOfRolls; i++)
{
int die1 = RollDie(); // Roll die 1
int die2 = RollDie(); // Roll die 2
int total = die1 + die2;
rollCounts[total]++;
}
// Display the results
Console.WriteLine("\nDICE ROLLING SIMULATION RESULTS");
Console.WriteLine("Each \"*\" represents 1% of the total rolls.");
Console.WriteLine($"Total number of rolls = {numberOfRolls}.\n");
for (int total = 2; total <= 12; total++)
{
int percentage = (rollCounts[total] * 100) / numberOfRolls;
Console.Write($"{total}: ");
for (int star = 0; star < percentage; star++)
{
Console.Write("*");
}
Console.WriteLine();
}
Console.WriteLine("\nThank you for using the dice throwing simulator. Goodbye!");
}
static int RollDie()
{
Random random = new Random();
return random.Next(1, 7);
}
}