Question

c language This assignment is to write a program to score the paper-rock-scissors game AGAIN. Each...

c language

This assignment is to write a program to score the paper-rock-scissors game AGAIN. Each of two players enters either P, R, or S. The program then announces the winner as well as the basis for determining the winner: “Paper covers rock”, “Rock breaks scissors”, “Scissors cut paper”, or “Draw, nobody wins”. The primary differences between this and previous two versions are described as below:

(1) You MUST use a function to get the input value for the player’s choice. The players must be able to enter either upper- or lower-case letters. If an invalid choice is entered, the player should be permitted to re-enter his choice immediately (before the other player is given a chance to enter their value). The function returns an enumerated type (e.g., Choice) that has possible three values, ROCK, PAPER, and SCISSORS (the one you defined in the previous version). This makes it so that the only part of your program that pertains to the player choices that can involve character variables is the input portion. The rest of your program should always use variables of the enumerated Choice type.

(2) you MUST use a function, e.g., checkWinner, to compare two choices, decide the winner, and print the result on the screen. This means that the function takes two Choice type arguments (i.e., player1’s choice and player2’s choice) and returns nothing.

The output should be like:

Player-1, please enter your choice <p>aper, <r>ock, or <s>cissors:

why?

I do not understand. Please enter your choice <p>aper, <r>ock, or <s>cissors:

42

I do not understand. Please enter your choice <p>aper, <r>ock, or <s>cissors:

Paper!

Player-2, please enter your choice <p>aper, <r>ock, or <s>cissors:

r

Player-1 wins! Paper covers rock!

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Executable Code:

#include<stdio.h>

typedef enum {

PAPER, ROCK, SCISSORS

} Choice;

Choice getInput()

{

char ch[50],avoid;

int c=0;

Choice input;

// asks the player to choose Rock, Paper, Scissors

while(c==0)

{

c=1;

printf("Please enter your choice <p>aper. <r>ock, or <s>cissors: ");

gets(ch);

if(ch[0]=='p'||ch[0]=='P')

input=PAPER;

else if(ch[0]=='r'||ch[0]=='R')

input=ROCK;

else if(ch[0]=='S'||ch[0]=='s')

input=SCISSORS;

else

c=0;

if(c==0)

{

printf("I am sorry! I do not understand!\n");

}

}

return input;

}

int main()

{

Choice p1,p2,avoid;

char reply='y';

while(reply=='y'||reply=='Y')

{

printf("Player-1 it is your turn!\n");

p1=getInput();

printf("Player-2 it is your turn!\n");

p2=getInput();

//display result

if(p1==p2)

printf("Draw, nobody wins!\n");

else if(p1==0 && p2==1)

printf("Player1 wins! paper covers rock!\n");

else if(p1==0 && p2==2)

printf("Player2 wins! Scissors cut paper!\n");

else if(p1==1 && p2==2)

printf("Player1 wins! Rock breaks scissors!\n");

else if(p1==1 && p2==0)

printf("Player2 wins! Paper covers rock!\n");

else if(p1==2 && p2==1)

printf("Player2 wins! Rock breaks scissors!\n");

else if(p1==2 && p2==0)

printf("Player1 wins! Scissors cut paper!\n");

printf("Do you wish to continue?(y/n): ");

reply = getchar();

scanf("%c",&avoid);//to clear buffer

}

system("pause");

return 0;

}



Sample Output:

Player-1 it is your turn! Please enter your choice <p>aper <r>ock, or <s>cissors: why !I do not understand! am sorry Please e



Please, comment below for any queries or modifications..
Please do rate the answer thanks..

Add a comment
Know the answer?
Add Answer to:
c language This assignment is to write a program to score the paper-rock-scissors game AGAIN. Each...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • This program should be in c++. Rock Paper Scissors: This game is played by children and...

    This program should be in c++. Rock Paper Scissors: This game is played by children and adults and is popular all over the world. Apart from being a game played to pass time, the game is usually played in situations where something has to be chosen. It is similar in that way to other games like flipping the coin, throwing dice or drawing straws. There is no room for cheating or for knowing what the other person is going to...

  • IN JAVA. Write a program that lets the user play the game of Rock, Paper, Scissors...

    IN JAVA. Write a program that lets the user play the game of Rock, Paper, Scissors against the computer. The program should work as follows. When the program begins, 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. Don’t display the computer’s choice yet....

  • C++ Part 2: Rock Paper Scissors Game Write a program that lets the user play this...

    C++ Part 2: Rock Paper Scissors Game Write a program that lets the user play this game against the computer. The program should work as follows: When the program begins, a random number between 1 and 3 is generated. If the number is 1, the computer has chosen rock. If the number is 2, the computer has chosen paper. If the number is 3, the computer has chosen scissors. Don't display the computer's choice yet. Use a menu to display...

  • (Java) Write a program that lets the user play the game of Rock, Paper, Scissors against...

    (Java) Write a program that lets the user play the game of Rock, Paper, Scissors against the computer. The program should work as follows. When the program begins, 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. Don’t display the computer’s choice yet. The...

  • Rock, Paper, Scissors (also known by several other names, see http://en.wikipedia.org/wiki/Rock p...

    Help needed in Perl language program! Note : Perl Language Rock, Paper, Scissors (also known by several other names, see http://en.wikipedia.org/wiki/Rock paper scissors) is an extremely popular hand game most often played by children. Often, it is used as a method of selection similar to flipping a coin or throwing dice to randomly select a person for some purpose. Of course, this game is not truly random since a skilled player can often recognize and exploit the non-random behavior of...

  • C++ You are asked to implement scissors-rock-paper game where the players are a computer and a...

    C++ You are asked to implement scissors-rock-paper game where the players are a computer and a user. The player that wins 3 hands successively is the winner of the game. Your program should prompt the user with a message at the beginning of each hand to enter one of scissors, rock or paper. If the user’s entry is not valid, i.e. entry is neither scissors, rock, nor paper, your program throws a message to the user to enter a valid...

  • In python language Write a program that lets the user play the game of Rock, Paper,...

    In python language Write a program that lets the user play the game of Rock, Paper, Scissors against the computer. The program should work as follows: 1. When the program begins, a random number in the range of 1 and 3 is generated. 1 = Computer has chosen Rock 2 = Computer has chosen Paper 3 = Computer has chosen Scissors (Dont display the computer's choice yet) 2. The user enters his or her choice of “Rock”, “Paper", “Scissors" at...

  • For this week’s assignment, we will be recreating the Rock, Paper, Scissors program using Object-...

    For this week’s assignment, we will be recreating the Rock, Paper, Scissors program using Object-Oriented Programming. You will be working with me on a team to build the program. I have already written my part of the program, and the Game.java file is attached. Your task will be to write a RockPaperScissors class that contains the following methods: getUserChoice: Has the user choose Rock, Paper, or Scissors. After validating the input, the method returns a String containing the user choice....

  • You are asked to implement scissors-rock-paper game where the players are a computer and a user....

    You are asked to implement scissors-rock-paper game where the players are a computer and a user. The player that wins 3 hands successively is the winner of the game. Your program should prompt the user with a message at the beginning of each hand to enter one of scissors, rock or paper. If the user's entry is not valid, i.e. entry is neither scissors, rock, nor paper, your program throws a message to the user to enter a valid entry...

  • Objective: Write a program that simulates a game of rock, paper, scissors between a human and...

    Objective: Write a program that simulates a game of rock, paper, scissors between a human and the computer in best 2 out of 3 rounds. Requirements: . The player can enter either "rock", "paper", or "scissors'". o If the player enters anything other than that the computer automatically gets a point . The computer randomly selects one of the gestures o Use the Random type to make this easier o Also make sure you import java.util.Random o You can use...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT