Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

2. Write a CH program that lets the user play the game of Rock, Paper, Scissors against the computer. The program should work as follows.

image text in transcribed
image text in transcribed
2. Write a CH program that lets the user play the game of Rock, Paper, Scissors against the computer. The program should work as follows. a) The program first determines the computer's play in the game, as follows: A random number in the range of 1 through 3 is generated. If the number is 1, then the computer has chosen "rock". If the number is 2, then the computer has chosen "paper". If the number is 3, then the computer has chosen "scissors". b) The program then prompts the user to enter her "rock", "paper", or "scissors" choice and then reads it, using the same number scheme as above. c) The program then displays both choices (in words) and the result of the play. A winner is selected according to the following game rules: If one player chooses rock and the other player chooses scissors, then rock wins. (The rock smashes the scissors.) If one player chooses scissors and the other player chooses paper, then scissors wins. (Scissors cuts paper.) If one player chooses paper and the other player chooses rock, then paper wins. (Paper covers rock.) If both players make the same choice, that play is a tie. . The program should repeatedly ask the user if she wants to play again and continues play (i.e., repeats steps 1-3, above) until she selects to end the game. After the user decides to end play, the program should display the overall results of the game - that is, how many times the user won, how many times the computer won, and how many ties there were. . Your program should be modular and must contain the following functions: Function main will be the program driver - it will repeatedly call the following functions to get the user's play selection, randomly generate the computer's play selection, determine the winner of a play, and tally the results. The repetition should continue until the user selects to exit the program, at which time it will call a function to display the final results. getcompSelection-this function will use the rand function to determine the . Your program should be modular and must contain the following functions: Function main will be the program driver - it will repeatedly call the following functions to get the user's play selection, randomly generate the computer's play selection, determine the winner of a play, and tally the results. The repetition should continue until the user selects to exit the program, at which time it will call a function to display the final results. getCompSelection-this function will use the rand function to determine the computer's play selection and return it. getUserSelection - this function will prompt for and read the user's play selection and return it. playResults - this function will take the computer's and user's play selections, as well as counters for determining the total play results, and will determine the play result and display it, and will also increment the counters appropriately. finalResults - this function will take the total play results counters and generate the final display. Extra code needed: a) You need to add these to your #includes list: #include #include b) You need to include this call to the srand function after your variable declarations in main in order to "seed" the rand function: srand(time(NULL))

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

How do you add two harmonic motions having different frequencies?

Answered: 1 week ago

Question

Write formal proposal requests.

Answered: 1 week ago

Question

Write an effective news release.

Answered: 1 week ago

Question

Identify the different types of proposals.

Answered: 1 week ago