Database System Concepts
Database System Concepts
7th Edition
ISBN: 9780078022159
Author: Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher: McGraw-Hill Education
Bartleby Related Questions Icon

Related questions

bartleby

Concept explainers

Question

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!
Expert Solution
Check Mark
Knowledge Booster
Background pattern image
Computer Science
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
Recommended textbooks for you
Text book image
Database System Concepts
Computer Science
ISBN:9780078022159
Author:Abraham Silberschatz Professor, Henry F. Korth, S. Sudarshan
Publisher:McGraw-Hill Education
Text book image
Starting Out with Python (4th Edition)
Computer Science
ISBN:9780134444321
Author:Tony Gaddis
Publisher:PEARSON
Text book image
Digital Fundamentals (11th Edition)
Computer Science
ISBN:9780132737968
Author:Thomas L. Floyd
Publisher:PEARSON
Text book image
C How to Program (8th Edition)
Computer Science
ISBN:9780133976892
Author:Paul J. Deitel, Harvey Deitel
Publisher:PEARSON
Text book image
Database Systems: Design, Implementation, & Manag...
Computer Science
ISBN:9781337627900
Author:Carlos Coronel, Steven Morris
Publisher:Cengage Learning
Text book image
Programmable Logic Controllers
Computer Science
ISBN:9780073373843
Author:Frank D. Petruzella
Publisher:McGraw-Hill Education