Stick or roll is a game involving two players, A and B, and a die with four faces (numbered 1, 2, 3, 4). The faces are equally likely to occur when the die is rolled. Player A rolls the die once and sticks with that number as the score or rolls it again and scores the sum of the two numbers. • If A's score is greater than 4 then A loses. • If A's score is 4 then A wins. If A's score is less than 4, then B rolls the die once and sticks with that number as the score or rolls it again and scores the sum of the two numbers. • If B's score is greater than 4 then B loses. • If B's score is 4 or less and equal to A's or less, then B loses. • If B's score is 4 or less and greater than A's, then B wins. Player B sticks on the first roll if that number wins and rolls again if it doesn't win and it is possible to win with a second roll. Some example games might be: • A rolls a 2, chooses to roll again and rolls a 3. A's score is then 5 so A loses and B wins. * A rolls a 2 and chooses not to roll again. B rolls a 2, so rolls again and rolls another 2. B's score is then 4, so B wins. • A rolls a 1, chooses to roll again and rolls a 2. B rolls a 2, rolls again and rolls a 3. B's score is then 5 so B loses and A wins. In solutions to the following questions express all probabilities exactly. a If A's score is 3, describe the ways in which B could win. b If A's score is 3, what is the probability that B wins? e IF A's score is 2, what is the probability that B wins? a Player A decides to stick if the first roll is 3 or 4, otherwise rolls again. What is the probability that A wins the game using this strategy?
Control structures
Control structures are block of statements that analyze the value of variables and determine the flow of execution based on those values. When a program is running, the CPU executes the code line by line. After sometime, the program reaches the point where it has to make a decision on whether it has to go to another part of the code or repeat execution of certain part of the code. These results affect the flow of the program's code and these are called control structures.
Switch Statement
The switch statement is a key feature that is used by the programmers a lot in the world of programming and coding, as well as in information technology in general. The switch statement is a selection control mechanism that allows the variable value to change the order of the individual statements in the software execution via search.
Stick or roll is a game involving two players, A and B, and a die with four faces (numbered 1, 2, 3, 4). The faces are equally likely to occur when the die is rolled. Player A rolls the die once and sticks with that number as the score or rolls it again and scores the sum of the two numbers. • If A's score is greater than 4 then A loses. • If A's score is 4 then A wins. If A's score is less than 4, then B rolls the die once and sticks with that number as the score or rolls it again and scores the sum of the two numbers. • If B's score is greater than 4 then B loses. • If B's score is 4 or less and equal to A's or less, then B loses. • If B's score is 4 or less and greater than A's, then B wins. Player B sticks on the first roll if that number wins and rolls again if it doesn't win and it is possible to win with a second roll. Some example games might be: • A rolls a 2, chooses to roll again and rolls a 3. A's score is then 5 so A loses and B wins. * A rolls a 2 and chooses not to roll again. B rolls a 2, so rolls again and rolls another 2. B's score is then 4, so B wins. • A rolls a 1, chooses to roll again and rolls a 2. B rolls a 2, rolls again and rolls a 3. B's score is then 5 so B loses and A wins. In solutions to the following questions express all probabilities exactly. a If A's score is 3, describe the ways in which B could win. b If A's score is 3, what is the probability that B wins? e IF A's score is 2, what is the probability that B wins? a Player A decides to stick if the first roll is 3 or 4, otherwise rolls again. What is the probability that A wins the game using this strategy?
Step by step
Solved in 4 steps with 3 images