Using C++ Write a program that plays a dice game called "21" It is a variation on BlackJack where one player plays against the computer trying to get as close to 21 as possible without going over. Here are the rules of the game: You will play with dice that have numbers from 1 to 11. To win, the player or the computer has to get to 21, or as close as possible without going over. If the player or computer goes over 21, they instantly lose. If there is a tie, the computer wins. Starting the game: The player is asked to give the computer a name. For now, we'll simply call the computer opponent, "computer." The game starts with rolling four dice. The first two dice are for the player. These two dice are added up and the total outputted to the screen. The other two dice are for the computer. Likewise, their total is outputted to the screen. Player Loop: If a total of 21 has been reached by either the player or the computer, the game instantly stops and the winner is declared. Otherwise, the player is asked if they want to roll one die that will be added to their total. Or they want to stop. The player should enter an 'r' to roll the die or an 's' to stop. The player may continue rolling until they have reached 21 or over. Finishing: If the player total is > 21 then the computer is declared the winner. Otherwise, the computer has to make a decision to roll or to stop. If the computer total >= the player total, the computer stops. If the computer total < the player total then the computer continues to roll one die until the computer total is >= the player total. The winner is declared!
Max Function
Statistical function is of many categories. One of them is a MAX function. The MAX function returns the largest value from the list of arguments passed to it. MAX function always ignores the empty cells when performing the calculation.
Power Function
A power function is a type of single-term function. Its definition states that it is a variable containing a base value raised to a constant value acting as an exponent. This variable may also have a coefficient. For instance, the area of a circle can be given as:
Using C++
Write a program that plays a dice game called "21"
It is a variation on BlackJack where one player plays against the computer trying to get as close to 21 as possible without going over.
- Here are the rules of the game:
- You will play with dice that have numbers from 1 to 11.
- To win, the player or the computer has to get to 21, or as close as possible without going over.
- If the player or computer goes over 21, they instantly lose.
- If there is a tie, the computer wins.
-
- Starting the game:
- The player is asked to give the computer a name. For now, we'll simply call the computer opponent, "computer."
- The game starts with rolling four dice.
- The first two dice are for the player. These two dice are added up and the total outputted to the screen.
- The other two dice are for the computer. Likewise, their total is outputted to the screen.
- Starting the game:
-
- Player Loop:
- If a total of 21 has been reached by either the player or the computer, the game instantly stops and the winner is declared.
- Otherwise, the player is asked if they want to roll one die that will be added to their total.
- Or they want to stop.
- The player should enter an 'r' to roll the die or an 's' to stop.
- Player Loop:
-
-
- The player may continue rolling until they have reached 21 or over.
-
-
- Finishing:
- If the player total is > 21 then the computer is declared the winner.
- Otherwise, the computer has to make a decision to roll or to stop.
- If the computer total >= the player total, the computer stops.
- If the computer total < the player total then the computer continues to roll one die until the computer total is >= the player total.
- The winner is declared!
- Finishing:
Trending now
This is a popular solution!
Step by step
Solved in 3 steps with 3 images