dimanche 8 mars 2015

C# Sorting an array in a two dice game

I should have an output as follows (after sorting the count, sum needs to be static to count. Ascending or descending):



// <<<EXAMPLE>>>

// Sun Count
// 7 8,079
// 8 6,866
// 6 6,590
// 5 5,318
// 9 5,276
// 10 3,929
// 4 3,873
// 11 2,721
// 3 2,717
// 12 1,327
// 2 1,314


Random rand = new Random();
int[] sum = new int[13];
const int ROLLS = 36000;
const int MIN = 1;
const int MAX = 7;

//Display table heading
Console.WriteLine("\n{0,5}{1,10}" +
"\n---------------", "Sum", "Count");

//Roll two dice, each separately

for (int roll = 0; roll < ROLLS; roll++)
sum[rand.Next(MIN, MAX) + rand.Next(MIN, MAX)]++;


//Display the sum of two dice and its frequency


for (int i = 2; i < sum.Length; i++)
{

Console.WriteLine("{0,5}{1,10}", i, sum[i]);



}

// Print length of each row
// Array.Sort(sum);
for (int i = 0; i < sum.Length; i++)
{
Console.WriteLine("Length of row {0} is {1}", i, sum[i]);
}


Console.ReadKey();




Aucun commentaire:

Enregistrer un commentaire