I need help with random dice c#

Results 1 to 2 of 2

Thread: I need help with random dice c#

  1. #1
    Join Date
    Dec 1969

    Default I need help with random dice c#

    Start by doing one throw of four coins. Only count the heads (if you want the number of tails you can take the number of heads away from four). Declare a variable (set to zero) to count the heads. Have a for loop which goes around four times. In the loop, generate a random number which is either 0 or 1. If it is 0 add 1 to the heads count (otherwise do nothing). For test purposes, output the result (when you are happy that this is working, delete the line that outputs the result before going on to the next stage).<BR><BR>When this is working, you need to put a for loop around all this code so that it can be repeated 100 times. You need to declare five variables to count the number of times the result is no heads, or 1 heads or 2 heads … or 4 heads. You can use a switch statement to decide which to increment. Output the value of these variables as soon as you have left the loop. Check that they add up to 100 each time you run the program.<BR><BR>Finally, you draw the graph. The best approach is to use two nested for loops, but you could have five for loops one after each other. In the inner for loop (or each of the five for loops) you should output an asterisk using Console.Write (the upper limit of the for loop should be the appropriate count from the previous section), and you should use Console.WriteLine as soon as you have left the loop to get ready for the next line.<BR><BR>Finally, put the legend on the left hand side showing how many heads/tails each row represents. You should then have something which looks like the sample output above.<BR>

  2. #2
    Join Date
    Dec 1969

    Default Above. (eop)


Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts