Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Program Specifications Write a program to play an automated game of Rock, Paper, Scissors. Two players make one of three hand signals at the same

Program Specifications Write a program to play an automated game of Rock, Paper, Scissors. Two players make one of three hand signals at the same time. Hand signals represent a rock, a piece of paper, or a pair of scissors. Each combination results in a win for one of the players. Rock crushes scissors, paper covers rock, and scissors cut paper. A tie occurs if both players make the same signal. Use a random number generator of 0,1, or 2 to represent the three signals.
Note: this program is designed for incremental development. Complete each step and submit for grading before starting the next step. Only a portion of tests pass after each step but confirm progress.
Step 0. Read starter template and do not change the provided code. Integer constants are defined for ROCK, PAPER, and SCISSORS. A seed is read from input to initialize the random number generator. This supports automated testing and creates predictable results that would otherwise be random.
Step 1(2 pts). Read two player names from input (string). Read number of rounds from input. Continue reading number of rounds if value is below one and provide an error message. Output player names and number of rounds. Assume each player name contains less than 40 characters. Submit for grading to confirm 2 tests pass.
Ex: If input is:
3 Anna Bert -3-44
Sample output is:
Rounds must be >0
Rounds must be >0
Anna vs Bert for 4 rounds
Step 2(2 pts). Use rand()%3 to generate random values (0-2) for player 1 followed by player 2. Continue to generate random values for both players until both values do not match. Output "Tie" when the values match. Submit for grading to confirm 3 tests pass.
Ex: If input is:
10 Anna Bert 1
Sample output is:
Anna vs Bert for 1 rounds
Tie
Tie
Step 3(3 pts). Identify winner for this round and output a message. Rock crushes scissors, scissors cut paper, and paper covers rock. Submit for grading to confirm 6 tests pass.
Ex: If input is:
39 Anna Bert 1
Sample output is:
Anna vs Bert for 1 rounds
Tie
Tie
Bert wins with scissors
Step 4(3 pts). Add a loop to repeat steps 2 and 3 for the number of rounds. Output total wins for each player after all rounds are complete. Submit for grading to confirm all tests pass.
Ex: If input is:
82 Anna Bert 3
Sample output is:
Anna vs Bert for 3 rounds
Anna wins with paper
Tie
Anna wins with rock
Anna wins with paper
Anna wins 3 and Bert wins 0
THIS IS IN C CODE I NEED HELP FINISHING THE CODE BELOW
int main(){
const int ROCK =0;
const int PAPER =1;
const int SCISSORS =2;
int seed;
scanf("%d", &seed);
srand(seed);
char player1[40];
char player2[40];
int rounds;
scanf("%s %s %d", player1, player2, &rounds);
if (rounds <=0){
printf("Rounds must be >0
");
while (rounds <=0){
scanf("%d", &rounds);
if (rounds <=0){
printf("Rounds must be >0
");
}
}
}
printf("%s vs %s for %d rounds
", player1, player2, rounds);
int p1_wins =0;
int p2_wins =0;
for (int i =0; i < rounds; i++){
int p1_move = rand()%3;
int p2_move = rand()%3;
if (p1_move == ROCK && p2_move == SCISSORS){
printf("%s wins with rock
", player1);
p1_wins++;
} else if (p1_move == SCISSORS && p2_move == PAPER){
printf("%s wins with scissors
", player1);
p1_wins++;
} else if (p1_move == PAPER && p2_move == ROCK){
printf("%s wins with paper
", player1);
p1_wins++;
} else if (p2_move == ROCK && p1_move == SCISSORS){
printf("%s wins with rock
", player2);
p2_wins++;
} else if (p2_move == SCISSORS && p1_move == PAPER){
printf("%s wins with scissors
", player2);
p2_wins++;
} else if (p2_move == PAPER && p1_move == ROCK){
printf("%s wins with paper
", player2);
p2_wins++;
} else {
printf("Tie
");
printf("Tie
");
}
}
if (p1_wins > p2_wins){
printf("%s wins %d and %s wins
", player1, p1_wins, player2);
} else if (p1_wins < p2_wins){
printf("%s wins and %s wins %d
", player1, player2, p2_wins);
} else {
printf("Bert wins with scissors");
}
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

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

Information Modeling And Relational Databases

Authors: Terry Halpin, Tony Morgan

2nd Edition

0123735688, 978-0123735683

More Books

Students also viewed these Databases questions

Question

How wide are Salary Structure Ranges?

Answered: 1 week ago