vendredi 8 septembre 2017

How to fill an array with random generated numbers in c#

I begun my career as a trainee developer in c# this week. Got an exercise in which I should write a c#-console code for a dice-program. The specifications of the programme are:

the user is asked to type in how often the dice may be rolled/thrown the result has to be displayed in %, for each eye/number of the dice like: the dice rolled 1 about 3% of x-Times. 2 was rolled 7% of x-Times by the dice and so on.. until 6 . because I'm a newb at all in c#, this is how far I came:

   var dict = new Dictionary<int, int>();

        foreach (var value in array)
        {
            if (dict.ContainsKey(value))
                dict[value]++;
            else
                dict[value] = 1;
        }

        foreach (var pair in dict)
            Console.WriteLine("Die Zahl {0} ist {1} mal vorhanden.", pair.Key, pair.Value);
        Console.ReadKey();

and

        Random diceRandom = new Random();
        int rollDice = diceRandom.Next(1, 7);
        Console.WriteLine(diceRandom);


        //Console.WriteLine("Es wurde eine:" + rollDice + "gewürfelt" );

        for (int i = 1; i <= 10; i++)
        {
            List<int> liste = new List<int>();
            var ausgabe = liste.Select(zahlen => rollDice % 2 == 0).ToList();
            rollDice = diceRandom.Next(1, 7);
            Console.WriteLine("Es wurde eine  "  + rollDice + "  gewürfelt.");
            Thread.Sleep(50);

My problems, I've not figured out how to ask the user for the input how often the dice has to be rolled ? The second thing with output in % shouldn't be a huge drama, cause I get it somehow and first code is a beginning of a solution for that spec. It's my first exercise.

Thanks, L.J.




Aucun commentaire:

Enregistrer un commentaire