I'm creating a 2 dice game rolling 100 times and giving the game statistics and it works, kind of. The problem is that the both die's total is 50 when die 1 could be like 68 and die 2 could be 32 (Dice 1: 68, Dice 2: 32). How could I accomplish that according to my code?
int[] Dice1 = new int[7];
int[] Dice2 = new int[7];
Random x = new Random();
for (int throw = 1; throw <= 50; throw++)
{
Dice1[x.Next(1, 7)]++;
Dice2[x.Next(1, 7)]++;
}
Console.WriteLine("Side | times");//How many times sides 1-6 appear.
for (int side = 1; side < Dice1.Length; side++)
{
Console.Write(" " + side + " ");
Console.WriteLine(Dice1[side] + Dice2[side]);
}
int total = Dice1.Sum() + Dice2.Sum();
Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~~");
Console.WriteLine("total of 1. Dice: " + Dice1.Sum());
Console.WriteLine("total of 2. Dice: " + Dice2.Sum());
Console.WriteLine("~~~~~~~~~~~~~~~~~~~~~~");
Console.Write("Total Sum: ");
Console.WriteLine(total);
OUTPUT:
http://oi60.tinypic.com/140vzid.jpg
If anyone has any idea how i can get this to work please answer, greatly appreciated.
Currently you're rolling 2 dice exactly 50 times (for a total of 100 die rolls). It sounds like you want to perform 100 die rolls in which each roll choses a die at random to roll. In this case, simply change your loop to loop 100 times, not 50, and instead of rolling both, choose one to roll:
for (int throw = 1; throw <= 100; throw++)
{
if(x.Next(0,2) == 0)
Dice1[x.Next(1, 7)]++;
else
Dice2[x.Next(1, 7)]++;
}
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.