Question

Design an application that uses the C# random generator to randomly roll a six face dice...

Design an application that uses the C# random generator to randomly roll a six face dice ( no 1 - no 6) . If the user rolled a 3, the user gets to roll the six face die again. You must use a switch statement to write the result /s of the random dice roll/s to the screen. Hint: You should have nested switches in your program

Homework Answers

Answer #1

using System;
class HelloWorld {
static void Main() {
  
Random rand = new Random();
while(true)
{
int a = rand.Next(1, 7); // generating the Random number between 1 and 6
switch(a)
{
case 1: Console.WriteLine("The user has rolled one (" + a + ")"); break;
case 2: Console.WriteLine("The user has rolled two (" + a + ")"); break;
case 3: Console.WriteLine("The user has rolled three (" + a + ")"); break;
case 4: Console.WriteLine("The user has rolled four (" + a + ")"); break;
case 5: Console.WriteLine("The user has rolled five (" + a + ")"); break;
case 6: Console.WriteLine("The user has rolled six (" + a + ")"); break;
}
if(a != 3) // if it is 3 the user will roll down again
{
break;
}
}
}
}
OUTPUT :

Know the answer?
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for?
Ask your own homework help question
Similar Questions
in C++ i need a random number generator, numbers 1-6, so a dice roll program.   
in C++ i need a random number generator, numbers 1-6, so a dice roll program.   
Dice Rolling) Write an application to simulate the rolling of two dice. The application should use...
Dice Rolling) Write an application to simulate the rolling of two dice. The application should use an object of class Random once to roll the first die and again to roll the second die. The sum of the two values should then be calculated. Each die can show an integer value from 1 to 6, so the sum of the values will vary from 2 to 12, with 7 being the most frequent sum and 2 and 12 being the...
Suppose you roll six-sided dice four times and write down the resulting four digit number. We...
Suppose you roll six-sided dice four times and write down the resulting four digit number. We sat that a number is "balanced" if it contains an equal number of even and odd terms. What is the probability that the result of rolling the die is balanced?
   Dice Game – Accumulator Pattern and Conditionals (40 pts) IN PYTHON Write a program dicegame.py...
   Dice Game – Accumulator Pattern and Conditionals (40 pts) IN PYTHON Write a program dicegame.py that has the following functions in the following order: in python Write a function roll that takes an int n and returns a random number between 1 and n inclusive. Note: This function represents a n sided die so it should produce pseudo random numbers. You can accomplish this using the random module built into python.         (3 pts) Write a function scoreRound that...
One of the most popular games of chance is a dice game known as “craps”, played...
One of the most popular games of chance is a dice game known as “craps”, played in casinos around the world. Here are the rules of the game: A player rolls two six-sided die, which means he can roll a 1, 2, 3, 4, 5 or 6 on either die. After the dice come to rest they are added together and their sum determines the outcome. If the sum is 7 or 11 on the first roll, the player wins....
In java create a dice game called sequences also known as straight shooter. Each player in...
In java create a dice game called sequences also known as straight shooter. Each player in turn rolls SIX dice and scores points for any sequence of CONSECUTIVE numbers thrown beginning with 1. In the event of two or more of the same number being rolled only one counts. However, a throw that contains three 1's cancels out player's score and they mst start from 0. A total of scores is kept and the first player to reach 100 points,...
1.The number showing on the upper face of a fair six-sided dice is observed when rolled....
1.The number showing on the upper face of a fair six-sided dice is observed when rolled. Consider events A and B defined as: A = the number observed is at most 2 B = the number observed is an even number Find: 1.P(A') 2.P(A or B) 2.Along the road near Bundamba State High School, there are traffic lights at two different locations. At the first location, the light is green 80.9% of the time. At the second location, the light...
JAVA: MUST BE DONE IN JAVA Assignment: Write algorithms and programs to play “non-betting” Craps. Craps...
JAVA: MUST BE DONE IN JAVA Assignment: Write algorithms and programs to play “non-betting” Craps. Craps is a game played with a pair of dice. In the game, the shooter (the player with the dice) rolls a pair of dice and the number of spots showing on the two upward faces are added up. If the opening roll (called the “coming out” roll) is a 7 (“natural”) or 11 (“yo-leven”), the shooter immediately wins the game. If the coming out...
Task #4 Calculating the Mean Now we need to add lines to allow us to read...
Task #4 Calculating the Mean Now we need to add lines to allow us to read from the input file and calculate the mean. Create a FileReader object passing it the filename. Create a BufferedReader object passing it the FileReader object. Write a priming read to read the first line of the file. Write a loop that continues until you are at the end of the file. The body of the loop will: convert the line into a double value...
1. A random number generator is used to select a number from 1 to 500 ?(inclusively)....
1. A random number generator is used to select a number from 1 to 500 ?(inclusively). What is the probability of selecting the number 595 ? What is the probability? 2.Identify the sample space of the probability experiment and determine the number of outcomes in the sample space. -Randomly choosing an even number between 10 and 20, inclusive The sample space is? (Use a comma to separate answers) There are _____ outcomes in the sample space 3. Determine the number...
ADVERTISEMENT
Need Online Homework Help?

Get Answers For Free
Most questions answered within 1 hours.

Ask a Question
ADVERTISEMENT