Question

Using If and else and switch, how would you write code that would display 3 every...

Using If and else and switch, how would you write code that would display 3 every time a 1 is rolled with any other numbered dice?

For example:

die roll 5, 1 = 3 , roll 4,1 =3 , roll 1,1 =3 and so on

die roll 1, 6 = 3 , roll 1, 4=3 , roll 1, 2= 3 and so on

Note: everything should roll the same unless a 1 is invovled

Thank-you

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Solution:

suppose x and y are the variables holding the value of the rolling dice.

so the values which they will be holding is

int x, y = {1, 2, 3, 4, 5, 6};

switch(x)

{

case 1:

cout<<"3"<<endl;

break;

case 2:

if(y==1)

cout<<"3"<<endl;

break;

case 3:

if(y==1)

cout<<"3"<<endl;

break;

case 4:

if(y==1)

cout<<"3"<<endl;

break;

case 5:

if(y==1)

cout<<"3"<<endl;

break;

case 6:

if(y==1)

cout<<"3"<<endl;

break;

}

I hope this helps if you find any problem. Please comment below. Don't forget to give a thumbs up if you liked it. :)

Add a comment
Know the answer?
Add Answer to:
Using If and else and switch, how would you write code that would display 3 every...
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. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • In python 3, Write a program in Python that simulates the roll of two dice. The...

    In python 3, Write a program in Python that simulates the roll of two dice. The first die is a 6-sided die. The second die is an 8-sided die. Generate a random number for a die and store it in variable number1. Generate a random number for a die and store it in variable number2. Note: Submit your code with the print("You rolled two dice:", number1, "and", number2) statement.

  • Complete each problem separately and perform in python. 1. Create a script that will roll five...

    Complete each problem separately and perform in python. 1. Create a script that will roll five dice and print out their values. Allow the user to roll the dice three times. Prompt them to hit enter to roll. Ex: Hit enter to roll 1,4,3,6,6 Hit enter to roll 3,5,1,2,1 Hit enter to roll 4,3,4,2,6 2. Write a script that will roll five dice (just one time). The user's score will be the sum of the values on the dice. Print...

  • Make a public class called ManyExamples and in the class... Write a function named isEven which...

    Make a public class called ManyExamples and in the class... Write a function named isEven which takes in a single int parameter and returns a boolean. This function should return true if the given int parameter is an even number and false if the parameter is odd. Write a function named close10 which takes two int parameters and returns an int. This function should return whichever parameter value is nearest to the value 10. It should return 0 in the...

  • 1. A standard six-sided die has a different number from 1 through 6 on each side,...

    1. A standard six-sided die has a different number from 1 through 6 on each side, with thoe average roll being a 3.5. Grime dice, on the other hand, have a different set of numbers of each side, with the same average roll as shown in the table. In this problem (or generally unless otherwise stated), we treat the dice as fair, such that any side is likely to be the top face when rolled Die Normal Red Grime Side...

  • Write a C program that prompts the user for the number for times the user wants...

    Write a C program that prompts the user for the number for times the user wants to flip a coin. Your program will flip a virtual coin that number of times and return the following: 1) The number of times heads occurred. 2) The number of times tails occured. Then take the coin flip program and modify the random number generator to roll a single 6-sided dice.   DO NOT DISPLAY THE RESULTS OF EACH ROLL. 1) Ask the user how...

  • (1 point) Using an if Statement In a Loop A common thing to do is to...

    (1 point) Using an if Statement In a Loop A common thing to do is to use variables to keep track of some sort of count. When used in a loop we count things very quickly. Scenario: If you roll a pair of dice, rolling a 12 (two sixes) is rare. How rare? If you were to roll a pair of dice 1,000 times, on average, how many times would it come up as 12? To figure this out, we...

  • Can anyone help me with this java program? We are still very early with lessons so...

    Can anyone help me with this java program? We are still very early with lessons so no advanced code please. And if you comment throughout the code that would be incredibly helpful. Thank you Create 2 Java files for this assignment: Die.java and TestDie.java Part 1 - The Die Class             The program Design a Die class that contains the following attributes: sides: represents how many sides a dice has. A dice usually has 6 sides but sometimes could have...

  • C# Code: Write the code that simulates the gambling game of craps. To play the game,...

    C# Code: Write the code that simulates the gambling game of craps. To play the game, a player rolls a pair of dice (2 die). After the dice come to rest, the sum of the faces of the 2 die is calculated. If the sum is 7 or 11 on the first throw, the player wins and the game is over. If the sum is 2, 3, or 12 on the first throw, the player loses and the game is...

  • in C++ This assignment is to use your knowledge of Chap 1-5 to write a simulation...

    in C++ This assignment is to use your knowledge of Chap 1-5 to write a simulation program to estimate the winning chance of the Craps game. Craps is a popular dice game played in casinos. Here is how to play: Roll two dice. Each die has 6 faces representing values 1,2,3,4,5,and 6, respectively. Check the sum of 2 dice. If the sum is 2, 3, or 12 (called craps), you lose; if the sum is 7 or 11 (called natural),...

  • Modular program mathlab: Write a program in Matlab that would continuously ask the user for an...

    Modular program mathlab: Write a program in Matlab that would continuously ask the user for an input between 1 and 6, which would represent the result of rolling a die. The program would then generate a random integer between 1 and 6 and compare its value to the value entered by user. If the user’s die is larger, it should display, “You got it” If the user’s die is smaller, it should display, “Nice try” If the results are the...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT