Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Database Processing Fundamentals Design

Authors: Marion Donnie Dutton Don F. Seaman

14th Edition Globel Edition

1292107634, 978-1292107639

More Books

Students also viewed these Databases questions

Question

What are Measures in OLAP Cubes?

Answered: 1 week ago

Question

How do OLAP Databases provide for Drilling Down into data?

Answered: 1 week ago

Question

How are OLAP Cubes different from Production Relational Databases?

Answered: 1 week ago