mercredi 6 septembre 2017

C# Random Number Percentage Probability - Roll the Dice

I'm currently working on a basic Dice Game that will show the percentage chance of the next dice roll.

My current code looks as such:

  private static void DiceGame()
    {
            Console.Clear();
            Console.WriteLine("Let's start by rolling the dice... \n");
            Console.WriteLine("Press ENTER to roll the dice: ");
            Console.ReadLine();

            Console.Clear();
            Random myRandom = new Random();
            int randomNumber = myRandom.Next(1, 7);
            Console.WriteLine("The Dice Rolled Number... {0}  \n", randomNumber);


            Console.WriteLine("The probability of your next role is: {0}");


        string result = Console.ReadLine();
    }

What code could I write in order to then display the odds of the next number that is going to be rolled? e.g."The probability of your next role is: 1 = 20% 2 = 25% 3 = 25% etc. "

I presume I will need an iteration in here also as the odds of rolling the same number over and over again will continuously decrease?




Aucun commentaire:

Enregistrer un commentaire