static void Main(string[] args) { Dice dice = new Dice(); int num = dice.Throw(); //Console.WriteLine("Number is {0}", num); Console.WriteLine("How many times you want to throw dice: "); string line = Console.ReadLine(); int times; bool success = int.TryParse(line, out times); if (success) { Random rand = new Random(); int[] collection = new int[times]; for (int i = 1; i < times; i++) { collection[i] = num; } double avrg = collection.Average(); Console.WriteLine("Dice is thrown " + times + " average is " + avrg); } else { Console.WriteLine("You didn't gave number"); } }
static void Main(string[] args) { Dice dice = new Dice(); Console.WriteLine("Give the amount of throws: "); string line = Console.ReadLine(); int amount = int.Parse(line); Console.WriteLine("Dice is now thrown " + amount + " times"); int number; int sum = 0; for (int i = 1; i <= amount; i++) { number = dice.Throw(); sum = sum + number; //Console.WriteLine("Dice value is {0}", number); } int average = sum/amount; Console.WriteLine("-average is {0}", average); }
static void Main(string[] args) { double average = 0; int loop, i = 0, value; int d1 = 0, d2 = 0, d3 = 0, d4 = 0, d5 = 0, d6 = 0; Dice dice = new Dice(); Console.Write("Kuinka monta kertaa noppaa heitetään? > "); string stuff = Console.ReadLine(); int.TryParse(stuff, out loop); do { value = dice.Throw(); average = average + value; switch (value) { case 1: d1++; break; case 2: d2++; break; case 3: d3++; break; case 4: d4++; break; case 5: d5++; break; case 6: d6++; break; } i++; } while (i < loop); average = average / loop; Console.WriteLine("Number of throws: " + loop + "\nAverage: " + average + "\n - Dice 1: " + d1 + "\n - Dice 2: " + d2 + "\n - Dice 3: " + d3 + "\n - Dice 4: " + d4); Console.WriteLine(" - Dice 5: " + d5 + "\n - Dice 6: " + d6); }
static void Main(string[] args) { Dice dice = new Dice(); Console.WriteLine("How many times you want to throw a dice?"); int times = int.Parse(Console.ReadLine()); Console.WriteLine("Dice values: "); int count = 0; int ones = 0; int twos = 0; int threes = 0; int fours = 0; int fives = 0; int sixes = 0; for (int i = times;i > 0; i--) { if (i == 0) break; count = dice.throwDice(); if (count == 1) ones++; if (count == 2) twos++; if (count == 3) threes++; if (count == 4) fours++; if (count == 5) fives++; if (count == 6) sixes++; } double average = (ones + (twos * 2.0) + (threes * 3.0) + (fours * 4.0) + (fives * 5.0) + (sixes * 6.0)) / times; Console.WriteLine("1: " + ones); Console.WriteLine("2: " + twos); Console.WriteLine("3: " + threes); Console.WriteLine("4: " + fours); Console.WriteLine("5: " + fives); Console.WriteLine("6: " + sixes); Console.WriteLine("Average dice: " + average); }