Question: 4. Edit this C# Rock Paper Scissors game below (algorithm & code) to validate the user's input. When the user enters something other than Rock,

4. Edit this C# Rock Paper Scissors game below (algorithm & code) to validate the user's input. When the user enters something other than Rock, Paper or Scissors he/she/they should be forced to reenter a choice. Also make sure curly brackets are properly placed if they are not already. ==============================================================================================

Algorithm: Display instructions Get uChoice Get cChoice (random number generator 1-4) if cChoice == ROCK (1) message = the computer chose ROCK else if cChoice == PAPER (2) message = the computer chose PAPER else cChoice == SCISSORS (3) message = the computer chose SCISSORS end if if uChoice == PAPER and cChoice == ROCK || uChoice == SCISSORS and cChoice == PAPER || uChoice == ROCK and cChoice == SCISSORS message = You win! else if uChoice == ROCK and cChoice == ROCK || uChoice == SCISSORS and cChoice == SCISSORS || uChoice == PAPER and cChoice == PAPER message = Tie! else message = You lose! end if Display message

public static void Main() { const int ROCK = 1; const int PAPER = 2; const int SCISSORS = 3;

Console.WriteLine("Let's play a game of Rock, Paper, Scissors! :) "); Console.Write("Please enter your choice: ROCK, PAPER, OR SCISSORS "); string uChoice = Console.ReadLine();

Random gen = new Random(); int cChoice = gen.Next(1, 4);

if (cChoice == ROCK) Console.WriteLine("The computer chose ROCK"); else if (cChoice == PAPER) Console.WriteLine("The computer chose ROCK"); else Console.WriteLine(The computer chose SCISSORS"); if ((uChoice == PAPER && cChoice == ROCK) || (uChoice == SCISSORS && cChoice == PAPER) || (uChoice == ROCK and cChoice == SCISSORS)) { Console.WriteLine("You win!" ); } else if ((uChoice == ROCK && cChoice == ROCK) || (uChoice == SCISSORS and cChoice == SCISSORS) || (uChoice == PAPER and cChoice == PAPER)) Console.WriteLine("Tie!" ); else Console.WriteLine("You lose!" );

Console.ReadLine(); }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!