Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

crap game figured out the following code but still needs to fix the following pr

ID: 3683215 • Letter: C

Question

crap game

figured out the following code but still needs to fix the following problems. any help is highly appreciated.

1. The output from each roll should indicate if it is the 1st roll and whether the player wins, loses or sets a point.

2. Allow the game to continue (in a loop) until the player decides to quit the game.3

#include<cmath>

#include<iostream>

using namespace std;

class Die

{

private:

int die1;

int die2;

int sum;

public:

Die();

int RollDice();

void CrapGame();

};

Die:: Die()

{

unsigned seed = time(0);

srand(seed);

cout<< "Initial Roll"<< endl;

}

int Die::RollDice()

{

die1= (rand() % 6) + 1;

die2= (rand() % 6) + 1;

sum = die1 + die2;

cout << "Player rolled " << die1 << "+" << die2 << "=" << sum <<endl;

return sum;

}

void Die:: CrapGame()

{

int myPoint;

enum Status { CONTINUE, WON, LOST };

Status gameStatus;

srand( time( 0 ) );

sum = RollDice();

switch(sum)

{

case 7: // win with 7 on first roll

case 11: // win with 11 on first roll

gameStatus = WON;

cout << "Player Rolled: " << sum << " Hence Wins." << endl;

break;

case 2: // lose with 2 on first roll

case 3: // lose with 3 on first roll

case 12: // lose with 12 on first roll

gameStatus = LOST;

cout << "Player Rolled: " << sum << " Hence Lost." << endl;

break;

default: // did not win or lose, so remember point

gameStatus = CONTINUE; // game is not over

myPoint = sum; // remember the point

cout << "Player Rolled: " << sum << " Hence Continue."

<< endl;

cout << "Point To Reproduce to Win is: " << myPoint << endl;

break; // optional at end of switch

} // end switch

// while game is not complete not won not lost

while ( gameStatus == CONTINUE )

{

sum = RollDice(); // roll dice again

// determine game status

// win by making point

if ( sum == myPoint )

{

gameStatus = WON;

cout << "Point Reproduced again. Hence Won" << endl;

break; // breaking the loop

}

// lose by rolling 7 before point

if ( sum == 7 )

{

gameStatus = LOST;

cout << "Lost by Rolling 7" << endl;

break; // breaking the loop

}

}//end while

// display won or lost message

if( gameStatus == WON )

cout << "Player wins" << endl;

else cout << "Player Losses" << endl;

}

int main(void)

{   

  

Die objGame;

objGame. CrapGame();

  

  

  

return 0;

}

post a question

Explanation / Answer

#include<cmath>
#include<iostream>
#include <cstdlib> /* srand, rand */
#include <ctime> // time
using namespace std;

class Die
{
private:
int die1;
int die2;
int sum;

public:
Die();
int RollDice();
void CrapGame();
};
Die:: Die()
{
unsigned seed = time(0);
srand(seed);
cout<< "Initial Roll"<< endl;
}
int Die::RollDice()
{
die1= (rand() % 6) + 1;
die2= (rand() % 6) + 1;
sum = die1 + die2;
cout << "Player rolled " << die1 << "+" << die2 << "=" << sum <<endl;
return sum;
}
void Die:: CrapGame()
{
int myPoint;
enum Status { CONTINUE, WON, LOST };
Status gameStatus;
srand( time( 0 ) );
sum = RollDice();
switch(sum)
{
case 7: // win with 7 on first roll
case 11: // win with 11 on first roll
gameStatus = WON;
cout << "Player Rolled: " << sum << " Hence Wins." << endl;
break;
case 2: // lose with 2 on first roll
case 3: // lose with 3 on first roll
case 12: // lose with 12 on first roll
gameStatus = LOST;
cout << "Player Rolled: " << sum << " Hence Lost." << endl;
break;
default: // did not win or lose, so remember point
gameStatus = CONTINUE; // game is not over
myPoint = sum; // remember the point
cout << "Player Rolled: " << sum << " Hence Continue."
<< endl;
cout << "Point To Reproduce to Win is: " << myPoint << endl;
break; // optional at end of switch
} // end switch
/* while game is not complete not won not lost */
while ( gameStatus == CONTINUE )
{
sum = RollDice(); // roll dice again
/* determine game status*/
/* win by making point*/
if ( sum == myPoint )
{
gameStatus = WON;
cout << "Point Reproduced again. Hence Won" << endl;
break; // breaking the loop
}
/* lose by rolling 7 before point */
if ( sum == 7 )
{
gameStatus = LOST;
cout << "Lost by Rolling 7" << endl;
break; // breaking the loop
}
}//end while
/* display won or lost message */
if( gameStatus == WON )
cout << "Player wins" << endl;
else cout << "Player Losses" << endl;
}

int main(void)
{   
Die objGame;
objGame. CrapGame();
return 0;
}