3 of a kind within a dice game

Updated on April 1, 2017 in [A] C# .Net
Share on Facebook0Tweet about this on TwitterShare on Google+0Share on Reddit0
0 on April 1, 2017

im having trouble with a program i am writing, which is a dice game,  which has 6 dice rolls, i want to implement code into this to show if there are any matches, e.g. Console.WriteLine(“You have three of a kind”); but i am unsure on how to do this, any help would be great thanks.

This is what i have so far… which produces 6 random dice rolls using an array

public static void Main(string[] args)
{
Contract.Requires(args != null);
var numberGenerator = new Random();

int[] diceRoll = new int[6];
diceRoll[0] = numberGenerator.Next(1, 7);
diceRoll[1] = numberGenerator.Next(1, 7);
diceRoll[2] = numberGenerator.Next(1, 7);
diceRoll[3] = numberGenerator.Next(1, 7);
diceRoll[4] = numberGenerator.Next(1, 7);
diceRoll[5] = numberGenerator.Next(1, 7);

for (int i = 0; i < diceRoll.Length; i++)
{
Console.Write( + diceRoll[i] + ” “);
}

Console.ReadKey();
}

  • Liked by
Reply