Hello, Looking for experts here that can help me codethese using " C# " Thank you in advance.
Assignment 2-20 Guesses. Out of /34 points Build a program that plays a game of 20 questions with the user. The user will think of a random whole number between 1 and 9999 and the computer will attempt to guess the user's number. To win, the computer needs to determine the user's secret number within 20 attempts. During each attempted guess, the computer will do the following: • Display the attempt counter (1, 2, 3..), • Display a number representing its 'guess' (See algorithm below), • Ask the user if its guess is higher (H), or lower (L) than the user's secret number, or if the computer has correctly guessed (Y) the user's secret number. • If the user selects Y (you can also use E), the application displays a message indicating the computer has won and ends the program • If the user selects an H or an L, the program increases the counter and, if the counter is less than 21 makes another attempt • If the counter exceeds, 20, the program displays a message indicating the user has won and exits the program Worded differently, • Before guessing the computer will announce how many guesses it has made • Each time the computer proposes a number, the user will reply with: o H) Higher - The number the user has chosen is higher than the guess provided by the computer o L) Lower - The number the user has chosen is lower than the guess provided by the computer o Y) Yes - The number the computer has guess is a match for the number chosen by the user. • If the user enters any other value than H, L or Y, it will indicate the error, and ask the user to select again. • If the user enters an H or an L, the computer will make another guess until it has reached a limit of 20 guesses. • If the user presses Y, then the computer has guessed the user's number and the computer Wins • If after 20 guesses, the computer has not guessed correctly, it will announce the user has won
The Algorithm The trick to guessing a number between 1 an 10000 is to use a principle of guessing the midpoint between the lower and upper bound of possible values. When the game starts, the user chooses a number between 1 and 10000. Therefore, the computer knows the lowest number the user could have choose is 1 and the largest is 10000. The mid pint between 1 and 10000 is 5000 (determined by adding 1 to 10000 and dividing the result by 2) • The computer's first guess will then be 5000. • Imagine the user has selected 3123. When asked if the user's number is higher or lower than 5000, the user will select L meaning lower. • • The computer now knows that the biggest possible value of the user's secret value is 4999 - It is lower than 5000. The new range of possible values is therefore 1 to 4999. The computer will then determine the midpoint between 1 and 4999 by adding the lower bound and the upper bound and dividing by 2: (1+4999)/2= 2500. (This is also known as the average of 1 and 4999) The computer's second guess will then be 2500 • Because the user's secret number is 3123, the user will select H to let the computer know their number is higher than the second guess of 2500. • When the user selects 'H' the computer now knows the user's secret number must now be larger that 2500 but less than 4999. The computer selects a midpoint between 2501 and 4999 by adding the values together and dividing by two as follows: (2500+4999)/2 = 3750 (truncate the decimal) The computer's third guess is then 3750 The user's number is lower so the upper bound of possible choice has narrowed to between 2500 and 3750. The computer calculates its guess by adding 2500 and 3750 and dividing by 2: 3125 • Again, the user's number is lower so the upper bound is adjusted to 3125 and the next guess is the midpoint between 2500 and 3125 = 2812 • User's number is higher, so the lower bound is adjusted to 2812. The next guess is between 2812 and 3125 = 2968 • User's number is higher, so the lower bound is adjusted to 2968. The next guess is between 2968 and 3125 = 3047 • User's number is higher, so the lower bound is adjusted to 3047. The next guess is between 3047 and 3125 = 3086 • User's number is higher, so the lower bound is adjusted to 3086. The next guess is between 3086 and 3125 = 3105 • User's number is higher, so the lower bound is adjusted to 3105. The next guess is between 3105 and 3125 = 3120 • User's number is higher, so the lower bound is adjusted to 3120. The next guess is between 3120 and 3125 = 3122 • User's number is higher, so the lower bound is adjusted to 3122. The next guess is between 3122 and 3125 = 3123
Hello, Looking for experts here that can help me code these using " C# " Thank you in advance.
-
- Site Admin
- Posts: 899603
- Joined: Mon Aug 02, 2021 8:13 am