Write a program to play rock, paper, scissor against the computer.

computer science

Description

Problem 1 (2+4+4=10 points). Write a program to play rock, paper, scissor against the computer. The game consists of two players drawing at the same time one of three hand gestures representing a rock, a paper or a scissor. The winner is determined according to the following rules: rock beats scissor, scissor beats paper, paper beats rock. If both players draw the same item, it is a tie.


1.1.) The computer should ask what item you have chosen (rock, paper, or scissor). The input should be entered as a character: 'r' for rock, 'p' for paper, 's' for scissor. Write your code to account for invalid inputs (by notifying the user the input is invalid and restarting the input prompt). The computer will then randomly draw one of the three items for its choice with equal probability using a random number generator. 

1.2.) Next, the computer will determine who the winner is (or if it is a tie) and report the result in the command line using fprintf( ). 


1.3.) The user should then be asked whether they want to play again or not. If the answer is ‘y’ (yes), the game should loop through steps 1.1-1.2 again. Otherwise, the game will stop and the computer will report (in the command line) how many times each player (you and the computer) won. 


Related Questions in computer science category