Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I am trying to write the code for a rolling game, I have finished the first part. When I try to write anything when it

I am trying to write the code for a rolling game, I have finished the first part. When I try to write anything when it asks " would you like to 'roll' or 'hold'?" it just repeats the question. Could someone help with this please. I will make sure to give a good feedback and an upvote.

image text in transcribedimage text in transcribedimage text in transcribedimage text in transcribedimage text in transcribed

Project 1: Pig Program DUE: Friday, March 5 (by 5:00 pm) Pig is a dice game with the following rules: Two players race to reach 100 points. Each turn, a player repeatedly rolls a die until either a 1 is rolled or the player holds and scores the sum of the rolls (i.e. the turn total). At any time during a player's turn, the player is faced with two decisions: roll - If the player rolls a o 1: the player scores nothing and it becomes the opponent's turn. 02-6: the number is added to the player's turn total and the player's turn continues. hold - The turn total is added to the player's score and it becomes the opponent's turn. The first player to score 100 or more points wins. For example, the first player, Ann, begins a turn with a roll of 5. Ann could hold and score 5 points, but chooses to roll again. Ann rolls a 2, and could hold with a turn total of 7 points, but chooses to roll again. Ann rolls a 1, and must end her turn without scoring. The next player, Bob, rolls the sequence 4-5-3-5-5, after which he chooses to hold, and adds his turn total of 22 points to his score. Your job is to write a C++ program in which the computer will play the user in a game of Pig. A key decision to build strategy for the computer player is how large a turn total should be risked to possibly get an even larger total. Use "hold at 20" strategy for your computer player (unless holding will win the game). (This will maximize the expected number of points per turn, though it does not maximize the expected probability of winning.) Below are bullet points describing specific behaviors your program should have. . Before every round, the program must output the following where xx is the user's score and Wy is the computer's score: New round: User: XX Computer: yy The user goes first. Before the user makes a decision, the program should tell them their current accumulated points and asks them what they would like to do using this exact prompt: You have zz points this round. Would you like to 'roll' or 'hold' ? The user should then input their request. If it is neither "roll" or "hold" they get the following message (where bad_command is whatever the user entered) and are reminded of their points and asked to make their decision again: I did not understand "bad_command", sorry. If the user decided to roll, they should be told their roll with the following message, and be prompted to decide what to do again: You rolled a n. If the user's roll ends their turn, they should be told the following: Sorry, your turn is over, and you gain points. If the user holds, they should be told how many points they held this turn and their new total (notice there is no period at the end of this line!): You held xx points, bringing you to yy Once it is the computer's turn, it pursues its "hold at 20" strategy. Every time it rolls, output that roll like so: The Computer rolled a n. If the computer rolls a 1, output the following message and end its turn: The Computer turn is over, and they gain points. If the computer manages to hold, output how many points they held this turn and their new total and end its turn: The Computer held xx points, bringing you to yy . At the end of the game output one of the following two lines: The Computer wins! or You win! The random dice rolls are supplied by a file 'rolls.txt". I provide a different set of rolls for each test I give it. Leave the first eight (8) lines of the main function alone. These load the dice rolls. You can access the next dice roll, and store it in an integer result, with the following excerpt of code: result = roll(); You must never re-roll the dice! That is to say, every time roll() is evaluated in your code, you must use that value as a dice roll! One hint you are re-rolling is if the Autograder is telling you that the dice rolls are not correct. EXPLORER C main.cpp X L SW > OPEN EDITORS V PROGRAMMING1-PROJECT1 > .vscode G helper.cpp Emain main.cpp M Makefile Project1.pdf Erolls.txt B G+ main.cpp > main(int, char * []) 1 #include 2 #include 3 using namespace std; 5 6 void init_rolls(string); 7 int rall(); A 9 int main(int argc, char sargv[]) 18 11 if (argc = 1) 12 { 13 init_rolls("rolls.txt"); 14 } 15 else 16 { 17 init_rolls(string(argv (11)); 1A } 19 20 //TODD: Your code here. 21 int user_score, computer_score, total_user_score, total_computer_score, results; 22 char str(10); 23 24 total_user_score = 0; 25 total computer score = @ 26 27 28 cout ss "New round" str PROBLEMS DUTPUT DEBUG CONSOLE TERMINAL 1: main + To I did not understand , sorry. Would you like to 'roll' or 'hold' ? roll I did not understand roll, sorry. would you like to 'roll' or 'hold' ? hold I did not understand hold, sorry. Would you like to 'roll' or 'hold' ? > OUTLINE OAD Ln 30, Col 43 Spaces: 4 UTF-8 LF C++ Mac 0 EXPLORER C main.cpp. G main.cpp > main(int, char * []) 37 38 while (str != "hold" || str != "roll") = " = ) 39 { 40 cout "I did not understand " a str ", sorry." > stri ge > OPEN EDITORS 1 UNSAVED PROGRAMMING1-PROJECT1 > .vscode G helper.cpp Emain main.cpp M Makefile Project1.pdf Erolls.txt www B 1 if ( str = "roll") { results = roll(); cout 1) 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 user_score - results; } cout str; } total_user_score = user score + results; PROBLEMS DUTPUT DERUG CONSOLE TERMINAL 1: main + To I did not understand , sorry. Would you like to 'roll' or 'hold' 7 roll I did not understand roll, sorry. Would you like to 'roll' or 'hold' ? hold I did not understand hold, sorry. Would you like to 'roll' or 'hold' ? > OUTLINE OAD Ln 72, Col1 Spaces: 4 UTF-8 LF C++ Mac EXPLORER C main.cpp ge www > OPEN EDITORS 1 UNSAVED PROGRAMMING1-PROJECT1 > .vscode G helper.cpp Emain main.cpp M Makefile Project1.pdf Erolls.txt B G+ main.cpp > main(int, char * O) 72 73 if ( str = "hold") { 75 cout OUTLINE OAD Ln 72, Col1 Spaces: 4 UTF-8 LF C++ Mac

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Time Series Databases New Ways To Store And Access Data

Authors: Ted Dunning, Ellen Friedman

1st Edition

1491914726, 978-1491914724

More Books

Students also viewed these Databases questions

Question

How do Data Types perform data validation?

Answered: 1 week ago

Question

How does Referential Integrity work?

Answered: 1 week ago