Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

In C language This program simulates two people playing the game rock-paper-scissors and prints the results after playing a number of games. The program first

In C language

This program simulates two people playing the game rock-paper-scissors and prints the results after playing a number of games. The program first prompts the user for the number of games to play. It then plays that many games. For each game, it generates two random numbers between 0 and 2 one for each player and determines the winner of that game. The program defines the following numbers: ROCK=0, PAPER=1, and SCISSORS=2, which allows you to do the following: int a = ROCK. The main program, shown below, counts the number of times each player won and then prints the results. For example, playing 10 games on the ZyBooks server generates the output:

There were 3 ties, 5 player one wins, 2 player two wins

Your job is to implement the three functions listed below. You are not allowed to modify anything else.

The following code is downloadable below under Submission Instructions.

#include  #include  #define ROCK 0 #define PAPER 1 #define SCISSORS 2 // Print the prompt, scan in an integer, and return it. int getInt(char prompt[]); // Return 0 for a tie, 1 if player 1 won, and 2 if player 2 won int findWinner(int p1move, int p2move); // Print three results in the order of ties / player1 wins / player2 wins void printResults(int numTies, int numP1Wins, int numP2Wins); int main(void) { int games = getInt("Enter the number of games to play: "); srand(0); int ties = 0, p1wins = 0, p2wins = 0; for (int a = 0; a < games; a++) { int p1 = rand() % 3; int p2 = rand() % 3; int ans = findWinner(p1, p2); if (ans == 0) ties++; if (ans == 1) p1wins++; if (ans == 2) p2wins++; } printResults(ties, p1wins, p2wins); return 0; }

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_2

Step: 3

blur-text-image_3

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

What is the data bus size of the Pentium processor ( in bytes )

Answered: 1 week ago