0

When I run the code it is outputting 0's for everything. Both rolls for the dice should be getting totaled and inserted into the array. It should roll both dice 36000 times and tally the results and output in the format. It will show me the proper format at the end however it does not insert any data into the array.

    using System;

    namespace DICE
    {
    public class DiceRoller
   {
    public static void Main()
    { // need to first create an object 
        Random random = new Random();

        // generate the int for use in the array

        int dice1;
        int dice2;

        // i need an  array to take these numbers and store them for use

        int[] dicerolls = new int[13];
        // I used 12 for the index for the max value but maybe I should use 6 for one dice at a time?
        for (int roll = 0; roll <= 36000; roll++) ;  //for loop to roll 36,000 times
        {
            dice1 = random.Next(6) + 1;
            dice2 = random.Next(6) + 1;

            int total = dice1 + dice2;

           dicerolls[total]++;
            //adds the 2 dice rolls to create one total for output
        }

        // then i need to display to frequency in which those numbers appear 
        Console.WriteLine("Sum     Frequency      Percentage");
        for (int roll = 2; roll < 13; roll++)
        {
            double percent = (dicerolls[roll] / 36000) * 100;
            Console.WriteLine("{0}\t {1}\t\t{2:0.00}", roll, dicerolls[roll], percent);
        }
    }
}

}

squillman
  • 13,363
  • 3
  • 41
  • 60
  • 1
    `roll++) ;` <-- remove that semicolon. That's the body of the loop and it's empty. What's in the curly braces that follow are not the body of the loop because of that semicolon. – madreflection Apr 16 '21 at 21:03
  • 2
    Learn [how to use the debugger](https://learn.microsoft.com/en-us/visualstudio/debugger/debugger-feature-tour?view=vs-2019). Stepping through the code, you would have seen that it stopped on the semicolon, ran the next block once, and then continued on instead of looping back another 36000 times. – madreflection Apr 16 '21 at 21:06
  • And by "stopped on the semicolon", I'm referring to the 36001 times it would highlight the semicolon as it executes nothing in the loop. – madreflection Apr 16 '21 at 21:18
  • 1
    You have a typo, as noted above. So all but the first count remain zero. The question ordinarily would be closed on that basis. But you also have a second bug where you later calculate the average, which would also lead to a result of 0. See duplicate for the reason for, and how to fix, _that_ bug. – Peter Duniho Apr 16 '21 at 21:22

0 Answers0