Only need help with saving and updating the scores Already h

Only need help with saving and updating the scores. Already have evey thing else. done

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.

Solve this program using the following incremental steps:

Copy this code into cloud9:

Solution

#include<iostream>
#include<cstdlib>
#include<ctime>

using namespace std;

const int PLAYER1 = 0;
const int PLAYER2 = 1;
const int WINNING_SCORE = 100;
int rollmyDice();


//FIXME (1): Implement the printIntro function
int printIntro(){
   cout<<\"\ Welcome to the Game.\";
   cout<<\"\ Rule for the game is as follow:\";
   cout<<\"\ Each turn, a player repeatedly rolls a die until either a 1 is rolled or the player decides to hold:\";
   cout<<\"       \    If the player rolls a 1, they score nothing and it becomes the next player\'s turn.\";
   cout<<\"       \    If the player rolls any other number, it is added to their turn total and the player\'s turn continues.\";
cout<<\"       \    If a player chooses to \\\"hold\\\", their turn total is added to their score, and it becomes the next player\'s turn.\";
   cout<<\"\ The first player to score 100 or more points wins.\ \ \ \";
}

//FIXME (4, 5, 6): Implement the humanTurn function
int humanTurn(string player,int playerscore){
   int currentScore = 0;
   int lastRoll;
char roh;
cout << \"Your total score is: \" << playerscore << \".\" << endl;
cout << \"Press r-roll again, h-hold.\" << endl;
cin >> roh;
while (roh == \'r\')
{
lastRoll = rollmyDice();
if (lastRoll == 1)
{
   cout << \"die value: 1,your turn over...\ \";
break;
}
else
{
currentScore += lastRoll;
cout << \"The die value: \"<<lastRoll ;
           cout<<\".\ Your current score is: \"<<currentScore;
cout << \"\ Press r-roll again, h-hold.\" << endl;
cin >> roh;
   }
}
while (roh== \'h\')
{
playerscore += currentScore;
break;
   }
return playerscore;

}
int rollmyDice()
{
   //this function holds the dice value from 1-6 and used to choose random value between 1-6
int temp;
int const start = 1, end =6;
srand (time(NULL));
temp = (start+(rand()%(end-start+1)));
return temp;

}


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<<\"\ Enter the player 1 name:\";
cin>>player1name;
cout<<\"\ Enter the player 2 name:\";
cin>>player2name;

//play game
while (player1score < WINNING_SCORE && player2score < WINNING_SCORE) {

//player 1\'s turn
if (turn == PLAYER1) {
   cout<<\"\ \"<<player1name<<\"\\\'s turn...\ \";
player1score = humanTurn(player1name, player1score);
turn=PLAYER2;
}
//player 2\'s turn
else {
   cout<<\"\ \"<<player2name<<\"\\\'s turn...\ \";
player2score = humanTurn(player2name, player2score);
turn=PLAYER1;
}

//FIXME (3): update turn value
// based on whose turn it is, update the turn variable to other player
//updated turn in the if else loop above

}

// FIXME (7): Output who won the game.
if(player1score>player2score)
   cout<<\"\ \"<<player1name<<\" won....!!!\";
  
   else if(player2score>player1score)
   cout<<\"\ \"<<player2name<<\" won....!!!\";
  
else if(player1score==player2score)
   cout<<\"\ Game draw...!!\";
return 0;
}

Only need help with saving and updating the scores. Already have evey thing else. done You are to finish the program below that implements the dice game PIG pla
Only need help with saving and updating the scores. Already have evey thing else. done You are to finish the program below that implements the dice game PIG pla
Only need help with saving and updating the scores. Already have evey thing else. done You are to finish the program below that implements the dice game PIG pla

Get Help Now

Submit a Take Down Notice

Tutor
Tutor: Dr Jack
Most rated tutor on our site