Question

In: Computer Science

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

Using:

Console App(.NET Framework)

Solutions

Expert Solution

using System;

namespace diceRoll
{
class Program
{
static void Main(string[] args)
{
//Random class to generate random number
Random random = new Random();
//To roll first time
int dice1 = random.Next(1, 7);
//Using switch case for each number on the dice
switch (dice1)
{
//If value on the dice is 1, then printing the value.
case 1:
Console.WriteLine("The rolled number on dice is {0}", dice1);
break;
//If value on the dice is 2, then printing the value.
case 2:
Console.WriteLine("The rolled number on dice is {0}", dice1);
break;
//If value on the dice is 3, then we need to get six value.
case 3:
Console.WriteLine("The rolled number on dice is {0}", dice1);
Console.WriteLine("The user gets to roll the six face die again");
//Rooling the dice second time, to get value 6
int dice2 = random.Next(1, 7);
//if dice2 value is not 6 then rolling again till 6 occurs
while (dice2 != 6)
{
Console.WriteLine("Ocuured value is {0}",dice2);
Console.WriteLine("It's not 6. So roll again till six occurs");
dice2 = random.Next(1, 7);
}
//Using switch case for dice2
switch (dice2)
{
//And the only case is 6
case 6:
Console.WriteLine("Six is occured.Done!");
break;
}
break;
//If value on the dice is 4, then printing the value.
case 4:
Console.WriteLine("The rolled number on dice is {0}", dice1);
break;
//If value on the dice is 5, then printing the value.
case 5:
Console.WriteLine("The rolled number on dice is {0}", dice1);
break;
//If value on the dice is 6, then printing the value.
case 6:
Console.WriteLine("The rolled number on dice is {0}", dice1);
break;
}
Console.ReadKey();
}
}
}


Related Solutions

You roll a six-faced dice and observe the number of dots on the top face. (a)...
You roll a six-faced dice and observe the number of dots on the top face. (a) Specify the appropriate sample space S of the random experiment. (b) Give an example of a partition of S. (Proof is unnecessary.) (c) Give an example of a probability mass function (pmf) for S.
A player pays $ 13 to roll three six-sided balanced dice. If the sum of the...
A player pays $ 13 to roll three six-sided balanced dice. If the sum of the 3 dice is less than 13, then the player will receive a prize of $ 70. Otherwise, you lose the $13. a. Find the expected value of profit.
. Three Dice of a Kind Consider the following game: You roll six 6-sided dice d1,…,d6...
. Three Dice of a Kind Consider the following game: You roll six 6-sided dice d1,…,d6 and you win if some number appears 3 or more times. For example, if you roll: (3,3,5,4,6,6) then you lose. If you roll (4,1,3,6,4,4) then you win. What is the probability that you win this game?
Suppose we roll a fair dice thrice in such a way that the assumption of random...
Suppose we roll a fair dice thrice in such a way that the assumption of random sampling is satisfied. Let {X1;X2;X3} be the numbers coming up in the first three throws. Let their sample average be X3= (1/3) * ((X1+X2+X3)) 1) Write down the sampling distribution ofX3. To this end, you need to write down a table that contains all values that X3 can take on together with their probabilities. 2) What is the probability that X3 greater than equal...
If I roll the six-sided dice 4times, Let N1 be the number of 2 and N2...
If I roll the six-sided dice 4times, Let N1 be the number of 2 and N2 be the number of 6 so what is the probability mass function of N1 and N2? and what is the covariance between two random variables
Roll two fair dice. Each die has six faces. A. Let A be the event that...
Roll two fair dice. Each die has six faces. A. Let A be the event that either a 3 or 4 is rolled first followed by an odd number. P(A) =  Round your answer to two decimal places. B. Let B be the event that the sum of the two dice is at most 7. P(B) =  Round your answer to two decimal places. C. Are A and B mutually exclusive events? (Yes or No) D. Are A and B independent or...
Roll two dice at the same time, and define a random variable X as the sum...
Roll two dice at the same time, and define a random variable X as the sum of the two faces observed. Determine the CDF and PMF of X. Sketch the CDF.
You roll two six-sided even dice. What is the probability that you get a score of...
You roll two six-sided even dice. What is the probability that you get a score of at least 11? a. 2/11 b. 1/12 c. 1/18 d. 1/6 
 
 You toss a fair coin 3 times in a row. What is the probability of getting at most two heads? a. 3/4 b. 1/4 c. 3/8 d. 7/8
If you roll two six-sided dice, what is the probability of obtaining the following outcomes? a)2...
If you roll two six-sided dice, what is the probability of obtaining the following outcomes? a)2 or 3 b) 6 and 4 c) At least one 5 d) Two of the same number (two 1s, or two 2s, or two 3s, etc.) e) An even number on both dice f) An even number on at least one die
Our experiment is to roll 2 dice 900 times. The random variable, X, is the number...
Our experiment is to roll 2 dice 900 times. The random variable, X, is the number of times that the two dice add up to either 7 or 11. Find E(X), Var(X), and E(X^2). Assuming that the Central Limit Theorem applies, AND that the standard deviation is exactly 12.5, AND not bothering with the half-unit correction, find: P(X>225) P(X<175)
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT