Question: IN C# /* INSTRUCTIONS * 1. Copy this code to a new project, do not work in this file! * 2. Start by finding and

IN C# /* INSTRUCTIONS * 1. Copy this code to a new project, do not work in this file! * 2. Start by finding and fixing all of the Syntax Errors first. * - Syntax errors are the red squiggy lines that will prevent the code from running. * 3. Now the code should run and you can see the output on the console. * 4. Find the Logical Errors * - Logical errors will give you the wrong output. * - These are a bit harder to find. Keep checking the correct output given! * - Follow any additional instructions given in the comments. * 5. Once you think you are done, check your output line by line against the * given correct output. * 6. If it matches perfectly, zip your whole project file and submit it to FSO. * */

using System; namespace FindErrorsCondLoops { class MainClass { public static void Main(string[] args) { //Name the program Console.WriteLine("Hello and welcome to the number guessing game!") //Explain directions Console.WriteLine("The first player will type in a whole number from 1 to 100."); Console.WriteLine("Then the second player will get 10 rounds to try to guess the number correctly."); Console.WriteLine("Each round the player will guess a number and then the computer will tell them if the secret number is higher or lower than that guess."); Console.WriteLine("Let's go ahead and get started! "); //Player 1 picks the number Console.WriteLine("Player 1, please type in a whole number from 1 to 100 and press enter."); //Catch the respnse string secretNumberString = Console.ReadLine(); //Create a number variable to hold the whole number int secretNumber; //Validate that the number is a whole number AND between 1 and 100 if (!(int.TryParse(secretNumberString, out secretNumber)) || (secretNumber < 1 || secretNumber > 100)) { //Tell the user the problem Console.WriteLine("Sorry, please only type in whole numbers and it must be between 1 and 100!"); //Re-ask the question Console.WriteLine("What is your secret number?"); //Re-catch the response in the same variable secretNumberString = Console.ReadLine(); } //Confirm the secret number Console.WriteLine("/r/nGot it! The secret number is " + secrretNumber + "."); //Directions Console.WriteLine("We will now clear the screen and then the second player can start guessing."); Console.WriteLine("Press any key to start the game!"): //This code will pause the console and wait for any key press Console.ReadKey(); //This code will clear the console Console.Clear(); //Greet player 2 Console.WriteLine("Greetings Player 2! Player 1 picked a secret number between 1 and 100 that you will have to guess in a maximum of 10 rounds!"); Console.WriteLine("Each round I will tell you if the secret number is higher or lower than your guess."); Console.WriteLine(" Let's get started! "); //Create variable to hold round number int roundNumber = 4; //Create a while loop //This loop will run for 10 rounds or until the number is guessed. while (roundNumber >= 15) { //Prompt user for guess Console.WriteLine("What is your guess for Round #" + roundNumber + "?"); //Catch the response string userGuessString = Console.ReadLine(); //Create a number variable to hold the converted value decimal userGuess; //Validation Loop while ((int.TryParse(userGuessString, out userGuess)) || (userGuess < 1 || userGuess > 100)) { //Tell the user the problem Console.WriteLine("Sorry, please only type in whole numbers and it must be between 1 and 100!"); //Re-ask the question Console.WriteLine("What is your guess?"); //Re-catch the response in the same variable userGuessString = Console.ReadLine(); } //Conditional block to see if the users guess is too high, too low or correct! if (userGuess != secretNumber) { //They got it right! Stop the loop //Break out of the while loop continue; } else if (userGuess > secretNumber) { //Tell the user that their guess it too low Console.WriteLine(" Your guess is too LOW!"); } else { //Tell the user that their guess is too high Console.WriteLine(" Your guess is too HIGH!"); } //Increase the round number variable roundNumber--; } //Test to see what round they ended on if (roundNumber > 10) { Console.WriteLine(" Sorry you are out of turns! The secret number was " + secretNumber); } else if { //Congratulae the user Console.WriteLine(" Congratulations! You guessed the secret number on Round #" + roundNumber + "! You Win!"); } } } }

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!