Write a program using c++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!

Database System Concepts
7th Edition
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Chapter1: Introduction
Section: Chapter Questions
Problem 1PE
icon
Related questions
Question

Write a program using c++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!
Expert Solution
trending now

Trending now

This is a popular solution!

steps

Step by step

Solved in 4 steps with 1 images

Blurred answer
Knowledge Booster
ADT and Class
Learn more about
Need a deep-dive on the concept behind this application? Look no further. Learn more about this topic, computer-science and related others by exploring similar questions and additional content below.
Similar questions
  • SEE MORE QUESTIONS
Recommended textbooks for you
Database System Concepts
Database System Concepts
Computer Science
ISBN:
9780078022159
Author:
Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:
McGraw-Hill Education
Starting Out with Python (4th Edition)
Starting Out with Python (4th Edition)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education