Click here to Skip to main content
15,795,793 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Write a simple game app that throws 2 dice until the numbers 1 is up on one die and the number 6 is up on the other die. Print the number of times that the dice were thrown.
*Create a static class called "Game" for this app.
*The Game class must have a static method called "ThrowDice" for trowing the 2 dice.
*The Game class must have a "DisplayIfo" method to display the outcome of time the 2 dice are thrown.
*The outcomes must be stored in List data type.
*Use C# property to access the List values.
*Use the List methods "Add", "Last" and "Count" to access the outcome.
*Use the "Program" class to run your "Game" class.

Sample Output:
Die 1   Die 2
-------   -----
4          5
2          6
1          6

 The dice were thrown 3 times.

What I have tried:

How do I delete this question from code project
Updated 26-Nov-20 4:40am
Patrice T 25-Nov-20 16:12pm    
And you have a question ?

Go back and read the question again: it contains some explicit instructions that you are completely ignoring ...
Share this answer
The List<t> is a collection of strongly typed objects that can be accessed by index and having methods for sorting, searching, and modifying list. It is the generic version of the ArrayList that comes under System.Collection.Generic namespace.

C# List<T> Collection[^]

Personally, I would create a "Throw" (Roll) class, and a List of Throws. The assignment seems to imply "one" list; but who knows.
Share this answer

Here is a tip. Use a value Tuple to store the dice rolls. You can define a roll of 2 dice like this

// to define and set the tuple as firstDice=0 secondDice=0
 (int firstDice, int secondDice) roll=(0,0);
//to set the first dice roll to an appropriate random  value between 1 and 6
 roll.firstDice = random.Next(1, 7);

You need to define a list to hold the value tuples and a suitable loop to roll the dice while you have not got the required values. As a check to see that your while condition is correct, the probability of no success after the second dice roll is 2/3*2/3=4/9. So the hit rate is 5/9=55% giving a average list size of 1.8.

Share this answer

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900