Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Please Comment each step! This assignment is designed to further enhance your understanding of loops and selection structures, as well as to develop you problem
Please Comment each step!
This assignment is designed to further enhance your understanding of loops and selection structures, as well as to develop you problem solving skills What to do Write a C program, that can guess any number between 1 and a maximum number by way of asking simple questions that can be answered with either 'Yes or 'No'. The form of the questions asked is generally something like this: "Is your number greater than XXX?" XXX will need to be computationally determined by your program and is part of your program's logic. The idea of the algorithm underlying your program's logic is that you continuously divide the range of numbers that contains the number to be guessed into two (roughly) equally sized sub-ranges and then determine which part the number to be guessed lies in using the simple kind of question mentioned above. Once you know in which range the number is, you cut the corresponding interval in half again, ask the question, cut the proper interval in half, ask, cut... you get the idea. You should convince yourself that your algorithm terminates when there is nothing to cut any more, which occurs exactly when the final interval has a length of 1, or, in other words, when the variables containing the smallest and the biggest number of the range contain the same number, which happens to be the number to be guessed I want you implement your program honoring these conventions I want you to implement the maximum number that could possibly be guessed as a symbolic constant named MAX. For the purpose of our assignment, I ask you to set MAX to 1000 I want you to read the yeso input from the user from the keyboard. We want to assume that entering the letter y means Yes and the letter n means No. Any other character is being ignored and results in the same question to be asked again I want you to number the questions starting at 1. Given the original range of numbers from 1 1000 For the most part, 10 questions will be asked, under rare circumstances, it may be nine questions you should never see more than 10 questions. To give you an idea what the output may look like, here is a run of the algorithm that tries to find the numb r 501 1. Is your number greater than 5007 (y) y 2. Is your number greater than 750? (y) n 3. Is your number greater than 6257 (y) n 4. Is your number greater than 563? (y) n 5. Is your number greater than 532? (y) n 6. Is your number greater than 516? (y) n 7. Is your number greater than 508? (y) n 8. Is your number greater than 5047 (y) n 9. Is your number greater than 502? (y) n 10. Is your number greater than 501? (y) nStep by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started