Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

C++ Program for Rock Paper Scissors with prompt? #include #include #include using namespace std; // function prototypes // convert a numeric choice to the corresponding

C++ Program for Rock Paper Scissors with prompt?

image text in transcribed

#include #include #include using namespace std; // function prototypes // convert a numeric choice to the corresponding string, // e.g. NUM_ROCK returns STR_ROCK string choiceNumToString(int choice_num); // get a random value between 1 and 3 (LIMIT) for the computer's choice int getComputerChoice(); // return true if ch is valid choice of NUM_ROCK, NUM_PAPER, or NUM_SCISSORS bool isValid(int ch); // get, validate, and return the human user's choice int getChoice(); // determine the winner - returns PLAYER_X or PLAYER_TIE int determineWinner(int choice1, int choice2); // global constants! const int RAND_LIMIT = 3; const int NUM_ERROR = 0; const int NUM_ROCK = 1; const int NUM_PAPER = 2; const int NUM_SCISSORS = 3; const string STR_ERROR = "error"; const string STR_ROCK = "rock"; const string STR_PAPER = "paper"; const string STR_SCISSORS = "scissors"; const int PLAYER_TIE = 0; const int PLAYER_1 = 1; const int PLAYER_2 = 2; int main() { unsigned seed = time(0); string inputStr; // general purpose string for input bool continuing = false; int player1_choice = 0, player2_choice = 0; int winner = 0; // seed the random number generator srand(seed); // main loop - ask the user if they want to play // and continue if confirmed do { cout > inputStr; if (inputStr != "y") continuing = false; else { continuing = true; cout  
Attached Files: rps.cpp 12.733 KB) The attached rps.cpp file contains an incomplete implementation of a program which plays the game rock, paper. scissors against the computer. Winners are mapped using the following combinations . Rock smashes scissors .Paper smothers rock Scissors cut paper .A tie occurs if the same object is chosen by both players. The file contains a fully functional main function and various useful constant definitions, as well as prototypes of the functions necessary to complete the implementation. Use these prototypes (and their associated descriptive comments) to implement the functions (below the main function, in the same file) so the program runs successfully. Do not modify any constant definition, function sgnature, or the main function (but read the hint provided below) Hint: you may want to start out by commenting cade in the main function and bring the commented lines back in piece-by-plece as you implement the functions. Remember to restore the entire main function hack to it's original state when complete so as not to break the rule about modifying the main function (what I don't see won't hurt me...). Sample output of the game is shown below Rock, Paper Scissors: play?(y or n y OK, let's play! Please enter your choice: 1 for ROCK 2 for PAPER 3 for SCISSORS:1 Tie game! Rock, Paper Scissors: play? ly or n OK let's play! Please enter your choice: y 1 for ROCK 2 for PAPER 3 for SCISSORS: 1 Computer chose paper, you chose rock Computer wins! Rock, Paper Scissors: play (y or ny OK, let's play! Please enter your 1 for ROCK 2 for PAPER 3 for SCISSORS:1 Computer chose scissors, you chose rock You win! Rock, Paper Sclssors: play? (y or n: n

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

More Books

Students also viewed these Databases questions

Question

Identify conflict triggers in yourself and others

Answered: 1 week ago