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 comput
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 comput
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
Related questions
Question
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 21 or as close to 21 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:
- 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.
- Player:
-
- Finishing the game:
- 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 the game:
-
- Writing this program (Main Assignment)(Use a Sheet of Paper) C++
- Use the top-down programming technique:
- Writing this program (Main Assignment)(Use a Sheet of Paper) C++
-
-
-
- Don't code right away.
- Take a piece of paper and write out the general things that need to happen like we talked about in "how to drive a car" in class.
- Break the problem down into smaller pieces.
- Then, turn those smaller pieces into functions and needed variables that are to be passed or referenced.
- Before you write a bunch of code.
- Make sure the general flow of your program works and test more complex
algorithms or unfamiliar c++ functions by themselves. - Use outputs within a function that simply say something like "Function _______ is calculating the random dice totals."
- Then, write the code for the functions.
- Start to address the small pieces, coding and testing things as you go.
- If it's too difficult or confusing, write a simple version that tests things out like random numbers.
- If you get the code working for one die, then you can get the code working for two dice, etc.
- Don't code right away.
-
-
Expert Solution
This question has been solved!
Explore an expertly crafted, step-by-step solution for a thorough understanding of key concepts.
This is a popular solution!
Trending now
This is a popular solution!
Step by step
Solved in 2 steps
Knowledge Booster
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.Recommended textbooks for you
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)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
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)
Computer Science
ISBN:
9780134444321
Author:
Tony Gaddis
Publisher:
PEARSON
Digital Fundamentals (11th Edition)
Computer Science
ISBN:
9780132737968
Author:
Thomas L. Floyd
Publisher:
PEARSON
C How to Program (8th Edition)
Computer Science
ISBN:
9780133976892
Author:
Paul J. Deitel, Harvey Deitel
Publisher:
PEARSON
Database Systems: Design, Implementation, & Manag…
Computer Science
ISBN:
9781337627900
Author:
Carlos Coronel, Steven Morris
Publisher:
Cengage Learning
Programmable Logic Controllers
Computer Science
ISBN:
9780073373843
Author:
Frank D. Petruzella
Publisher:
McGraw-Hill Education