Question
C++ coding, spacing/lining problem: Pig Dice Game You are to finish the program below that implements the dice game PIG played by 2 human players.
C++ coding, spacing/lining problem:
Pig Dice Game You are to finish the program below that implements the dice game PIG played by 2 human players. Pig is a dice game where each player during their turn rolls a 6-sided die. If the player rolls a 2 through 6, they decide whether they want to keep their turn score or roll again. If they roll a 1, the player loses all the points for that turn, thus receiving a turn score of 0 and that turn is over. The first player to reach 100 points or more wins. Sample output of program as it would look in cloud9:
Solve this program using the following incremental steps:
Copy this code into cloud9:
#include#include #include using namespace std; const int PLAYER1 = 0; const int PLAYER2 = 1; const int WINNING_SCORE = 100; //FIXME (1): Implement the printIntro function //FIXME (4, 5, 6): Implement the humanTurn function int main() { srand(4444); // setup and initialize variables int turn = PLAYER1; int player1score = 0; int player2score = 0; string player1name; string player2name; printIntro(); // FIXME (2): get names of players //play game while (player1score You can submit to zyBook after each step to get feedback.
(Step 1) Implement the printIntro function (This is Test 1)
(Step 2) Get the names of the 2 players (This is Test 2)
(Step 3) Implement the logic to switch who's turn it is in main function.
(Step 4) Implement humanTurn function to roll once (This is Test 3)
(Step 5) Implement humanTurn function to keep rolling until player answers n. (This is Test 4)
(Step 6) Implement humanTurn function to end when player rolls a 1. (This is Test 5)
(Step 7) Finish main function to output who won. (Last test will test entire program)
Sample cloud9 output showing winner:
This is my code:
#include
#include #include #include using namespace std;
const int PLAYER1 = 0; const int PLAYER2 = 1; const int WINNING_SCORE = 100;
//FIXME (1): Implement the printIntro function void printIntro(){ cout > rollAgain; cout > rollAgain; cout
int main() { srand(4444);
// setup and initialize variables int turn = PLAYER1; int player1score = 0; int player2score = 0; string player1name; string player2name; printIntro();
// FIXME (2): get names of players cout > player1name; cout > player2name; cout
//play game while (player1score
//player 1's turn or player 2's turn if (turn == PLAYER1) { player1score = humanTurn(player1name, player1score); turn = PLAYER2; } else { player2score = humanTurn(player2name, player2score); turn = PLAYER1; } } // FIXME (7): Output who won the game if(player1score >= WINNING_SCORE){ cout
return 0; }
Here are my errors and what I should be getting:
Thank you!
zyBooks Library cs10 home 5.12: PROGRAM 6: Pig Dice Game Player 1 Enter your name Aragorn Player 2 Enter your name: Legolas Aragorn You rolled a 6 Your score: 6 Do you want to roll again? (y) y Aragorn You rolled a 2 Your score 8 Do you want to roll again? y) y Mragorn You rolled a 6 Your score 11 Do you want Lo roll again? (y) n Logo las You rollod a M Your score: A Do you want roll again? y) y Loyola You olled a b Your score 9 Do you want Lo roll again. y) n Aragorn You rollod a 6 Your score 20 Do you want to roll again? (y) y Aragorn You rolled a 1 (PIG Your turn is over Your score: 14 Legolas You rolled a 2 Your score 11 Do you want to roll again (y)
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started