Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

///////////////////////////////////////////////////////////////////// // This program simulates a two player game of Pig. Both players are // computer simulated, but the user is able to choose the

///////////////////////////////////////////////////////////////////// // This program simulates a two player game of Pig. Both players are // computer simulated, but the user is able to choose the strategy // for each player. // // This program makes use of functions. Because we have two players // we are repeating certain actions in the game (asking for the // players' strategy and performing the actions for a turn of the // game for each player). Functions allow us to write the code one // time (in the function), then call the function each time we want // to use that block of code. We use parameters (values passed to // the function) to give the function different values to work with. // ///////////////////////////////////////////////////////////////////// #include #include #include #include using namespace std; int playerRoll(int strat, string name); int getStrat(string name); //////////////////////////////// // Note: It is best to not work on this program in the order that things are // written in this file. Start by writing pseudocode, then write the function // prototypes, followed by the functions, and finally write the main function. //////////////////////////////// //////////////////////////////// // Put the function prototypes here // You will write three functions: One to get the player's strategy from user // input, another to simulate a turn of the game, and a third to print the // game results. // End of function prototypes. Move on to write the block of code in the // main function //////////////////////////////// int main() { int total_player1 = 0; // Player 1 score tracker int total_player2 = 0; // Player 2 score tracker int player1_strat; // Player 1's strategy for each turn int player2_strat; // Player 2's strategy for each turn // seed the random number generator. // Notice that we seed the random number generator in the main function // (not in the player roll function), and we make sure not to put the // random number generator inside a loop. This is because we only want // to seed the random number generator ONCE per program run. srand(static_cast (time(NULL))); //////////////////////////////// // Write code from here until the end comment. Use the comments as guidelines. // Get the strategy for each player (use a function). // You should write a single function and call it twice (once for // each player). // Use a loop to have the two players continue to take turns until one of // has a total game score of 100 or greater. If the first player wins, make // sure that you don't allow the second player to take a turn (quit the loop // as soon as one player reaches 100 or greater). // // Use a function for the player's turn. You should write a single function // and call it two times (once for each player's turn). // End of your code block in the main function. // Move on to write the three functions below the main function. //////////////////////////////// // Print the results // NOTE - you need to write the printResults function if(total_player > total_player2) { printResults("Player 1", total_player, "Player 2", total_player2); } else if(total_player2 > total_player) { printResults("Player 2", total_player2, "Player 1", total_player); } else { // This should never happen because we quit the loop if Player 1 // wins and don't allow Player 2 to play their last turn. // But we'll put this in just for completeness. cout << "Draw! "; cout << "(Note: if this happens there is something wrong with the code)"; cout << endl; } return 0; } // end of main function ////////////////////////// // Write the following three functions // // Function that gets the player's strategy from user input. // This function should get the strategy for a single player and return // the "roll until" value. // This function checks that the user entered an integer, and // keeps prompting the user to enter an integer until an integer is entered. // // // Function that simulates a single player's turn. This function should return // the total of the rolls for the turn. // // // Function that prints the results of the game. See the example program output // to see how the end of game message should look. // This function is already called by the main program so you can look there to // see what return type and parameters it needs. // // End of your code for this program ////////////////////////// 

// Help me please:'(

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

Successful Keyword Searching Initiating Research On Popular Topics Using Electronic Databases

Authors: Randall MacDonald, Susan MacDonald

1st Edition

0313306761, 978-0313306761

More Books

Students also viewed these Databases questions

Question

What is database?

Answered: 1 week ago

Question

What are Mergers ?

Answered: 1 week ago

Question

=+professionalism and competency in handling global HR issues?

Answered: 1 week ago