Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

can someone help me with this problem? High/Low Guessing Game (in reverse) You certainly are familiar with the classic childrens game of Im thinking of

can someone help me with this problem?

High/Low Guessing Game (in reverse) You certainly are familiar with the classic childrens game of Im thinking of a number between 1 and 100 and then guessing what that number is. Its typical for a computer program to pick a number (randomly generated) and then have you guess what that number is. The computer then responds with whether your guess was too high, too low, or exactly right. To minimize the number of times it takes to guess the correct number, we begin by halving the values available to us. So, if the number is between 1 and 100, we start by guessing 50. Then, if that guess is incorrect, we halve the field again; in the case of our initial guess being too high then our next guess would be 25. This continues until the number is revealed. In reality, we are performing a binary search. For this daily, you will prompt the user for the minimum number, the maximum number, and the actual number. In effect, you are telling the computer that I am guessing a number from n1 to n2 and the guessed number is n. Your application will then perform a loop in which the computer guesses the value of n and tells you how many attempts it took to do so. Steps: Prompt the user for three values: min, max, and actual selected number. Using a loop of your choice (for, while, or do) construct your code such that the computer finds your guessed number in the least number of tries. Output to the user each guessed number and finally the count of the number of times it took the computer to find your number. Finally, calculate what the maximum number of guesses should be if the logic of your code is correct. This calculation can simply be expressed as log base 2 of n, where n is the total number. Notes: To calculate the log base 2 of n value, we will use the following code substituting the actual total number of possible numbers in place of n: Math.log(n) / Math.log(2); For example, if I am guessing a number of between 1 and 1000, the calculation would simply be Math.log(1000) / Math.log(2);

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

More Books

Students also viewed these Databases questions

Question

6. What is process reengineering? Why is it relevant to training?

Answered: 1 week ago