Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

I need to write a code in C language but not in C++. Write a program that implements a Rock Paper Scissors game that allows

I need to write a code in C language but not in C++.

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

image text in transcribed

Write a program that implements a Rock Paper Scissors game that allows the user to play the computer. The program should prompt the user to enter R, P,or S for Rock, Paper, or Scissors then it should randomly generate the computer's choice and determine who won and displa the result. The program should allow the user to continue playing until the user decides to stop, displaying the score (number of times that the computer won, the number of times tha the player won and the number ofties). In this game, Rock beats (breaks) Scissors, Scissors beats (cuts) Paper, and Paper beats (covers) Rock. The program should do error handling on the input values and require the Player toentei R, P, S or Q (for quit). The program should accept both upper and lower case letters. The program output should look like the example output in the last section, including spacing ano error handling. 1 Block Conments You should include a block comment in the following format atop of all ofyour programs your program and line comments as needed throughout Program Name: CoF 2220 Project 2 - Description ROJECT-DESCRIPIION *Author: YOUR-NAME -Date HEN-LAST-MODIFIED Each function (other than main) must start with a comment block formatted as follows: Function Name FUNCTION-NAME Input ParametersHAI FUNCTION-TAKES Description: MHAT-FUNCTION-DOES *Return Value MHAT-FUNCTION-RETURNS 2 Other Requirements 1. The program must use at least three functions, excluding the flushScanf function provided below, with appropriate parameters and retun values in addition tomain. 2. Make sure that your project is organized with function declarations, then the main function, then the other functions. 3. You must not use global variables 4. The program must use at least one while or for loop 5. The program must use at least one switch statement. 6. The program must use at least one if...else if...elsemulti-way statement. 7. The program must randomly choose the computer's choice or R, P,or S. 8. Avoid the use of hard coded numbers. Use constants instead. 4 Flushing scanf You will find the following function Elushscanf useful when handling erroneous user inputs, e.g., the user inputs "lock". It is a good practice calling function flushScanf right after a scanf statement. void flushScanf (void) char C while ((c= getchar ( )) ! , ' && c != EOF) ote that your program should include error handling. Let's play a game of Rock/Paper/Scissors Enter the R, , S, or 2 (for quit): Hey Error: Invalid choice, try again. Enter the R, , S, or 2 (for quit): R You picked Rock, the computer pickd Paper. Paper covers Rock, the computer wins! Enter the R, , S, or (for quit): r You picked Rock, the computer picked Scissors Rock breaks Scissors, you win! Enter the R, , S, or (for quit): 2 Error: Invalid choice, try again. Enter the R, , S, or (for quit) s You picked Scissors, the computer picked Paper. Scissors cut Paper, you win! Enter the R, , S, or (for quit): S You picked Scissors, the computer picked Scissors Me picked the same thing, it is a tie. Enter the R, , S, or (for quit): S You picked Scissors, the computer picked Rock. Rock breaks Scissors, the computer wins! Enter the R, , S, or (for quit): p You picked Paper, the computer picked Rock. Paper covers Rock, you win! Enter the R, , S, or (for quit):R You picked Rock, the computer picked Rock. Me picked the same thing, it is a tie. Enter the R, , S, or (for quit) You won 3 times, the computer won 2 times and it was a tie 2 times

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access with AI-Powered 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

Students also viewed these Databases questions