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); }