Question: Write a C program using binary search. The program is guessing a number within the range that you set. The maximum and minimum is -1000000

Write a C program using binary search. The program is guessing a number within the range that you set. The maximum and minimum is -1000000 and 1000000. The program will make its first guess and the user will either "yes!!!" or "no" depending if it is correct or not. If it guesses wrong and the user inputs "no" then the program will guess again. If the next guess is closer to the value the user will input "Warmer" if it is farther the user will input "Colder". The program will find the mid between the last value and the max to guess again until it guesses correctly or runs out of guesses.

Write a C program using binary search. The program is guessing a

number within the range that you set. The maximum and minimum is-1000000 and 1000000. The program will make its first guess and the

Problem Given a range of numbers to guess ([1,n]), guess the correct integer in the range in less than 1+2*cieling(log, (n)) tries. Input Output Interaction You should begin by reading a line containing 1 integer, n (1=n 1,000,000), representing the maximum positive integer that Patty can choose. You will then perform a series of guesses. Each guess will requiring your program to output an integer in the range of [-1000000000, 1000000000]. Values outside that range will be treated as invalid. For a valid guess a single line will be output. If the guess is correct the line will begin with "Yes!!!". If the guess is incorrect the line will begin with "No.". For every guess after there is extra output. If the value is closer than the previous to the target, the word "Warmer." will be printed separated from the first word by a space. If the value is further than the previous to the target, the word "Colder. will be printed separated from the first word by a space. If the value is neither closer nor further than the previous to the target, the words No change." will be printed separated from the first word by a space. If your program takes too many guesses after the last "No." line the phrase "Game Over" will be outputted. IMPORTANT: After every printf(...); in your program please use the line of code fflush(stdout); to tell my judger to read in the next line. Sample Interaction 1 Input (The text your program reads in) Output (your program's prints) 10 5 No 10 No. Colder. 3 No. Colder. 7 Yes!!! Explanation Interaction 1 The answer is 7 with a maximum value of 10. Your program only reads that 10 is the maximum value. You can try any value you want, but the sample tries the value 5 first. That is not correct. The next attempt the sample tries is 10. The value 5 was closer to 7 than what 10 is, because the difference between 5 and 7 is 2, but the difference between 10 and 7 is 3. Thus the output is "No. Colder." The next attempt the sample tries is 3. The value 3 is further from 7 than what 10 was, because the difference between 7 and 3 is 4, where the difference between 7 and 10 is 3. Thus the output is yet again "No. Colder." 7 is the only value that fits that pattern, so 7 is outputted and the next line of input given to the program is "Yes!!!". After "Yes!!!" is read in, the program needs to terminate (return 0). Interaction 2 The answer is 13 with a maximum value of 20. The first guess which is wrong was 3. The second guess which is wrong but closer ("Warmer") is 15. The value i warmer because the difference between 3 and 13 = 10, but the difference between 15 and 13 = 2. The third guess which is wrong and further ("Colder") is 20. The value is colder, because the difference between 15 and 13 = 2 and the difference between 20 and 13 = 7. The fourth guess which is also wrong ("Warmer") was 10. The value is warmer because the difference between 10 and 13 = 3, but difference between 20 and 13 = 7. The fifth guess which is also wrong ("No change.") was 16. The value has no change because the difference is identical between the two guesses (3). The last guess is 13, because we should know that the midpoint would be the answer. Problem Given a range of numbers to guess ([1,n]), guess the correct integer in the range in less than 1+2*cieling(log, (n)) tries. Input Output Interaction You should begin by reading a line containing 1 integer, n (1=n 1,000,000), representing the maximum positive integer that Patty can choose. You will then perform a series of guesses. Each guess will requiring your program to output an integer in the range of [-1000000000, 1000000000]. Values outside that range will be treated as invalid. For a valid guess a single line will be output. If the guess is correct the line will begin with "Yes!!!". If the guess is incorrect the line will begin with "No.". For every guess after there is extra output. If the value is closer than the previous to the target, the word "Warmer." will be printed separated from the first word by a space. If the value is further than the previous to the target, the word "Colder. will be printed separated from the first word by a space. If the value is neither closer nor further than the previous to the target, the words No change." will be printed separated from the first word by a space. If your program takes too many guesses after the last "No." line the phrase "Game Over" will be outputted. IMPORTANT: After every printf(...); in your program please use the line of code fflush(stdout); to tell my judger to read in the next line. Sample Interaction 1 Input (The text your program reads in) Output (your program's prints) 10 5 No 10 No. Colder. 3 No. Colder. 7 Yes!!! Explanation Interaction 1 The answer is 7 with a maximum value of 10. Your program only reads that 10 is the maximum value. You can try any value you want, but the sample tries the value 5 first. That is not correct. The next attempt the sample tries is 10. The value 5 was closer to 7 than what 10 is, because the difference between 5 and 7 is 2, but the difference between 10 and 7 is 3. Thus the output is "No. Colder." The next attempt the sample tries is 3. The value 3 is further from 7 than what 10 was, because the difference between 7 and 3 is 4, where the difference between 7 and 10 is 3. Thus the output is yet again "No. Colder." 7 is the only value that fits that pattern, so 7 is outputted and the next line of input given to the program is "Yes!!!". After "Yes!!!" is read in, the program needs to terminate (return 0). Interaction 2 The answer is 13 with a maximum value of 20. The first guess which is wrong was 3. The second guess which is wrong but closer ("Warmer") is 15. The value i warmer because the difference between 3 and 13 = 10, but the difference between 15 and 13 = 2. The third guess which is wrong and further ("Colder") is 20. The value is colder, because the difference between 15 and 13 = 2 and the difference between 20 and 13 = 7. The fourth guess which is also wrong ("Warmer") was 10. The value is warmer because the difference between 10 and 13 = 3, but difference between 20 and 13 = 7. The fifth guess which is also wrong ("No change.") was 16. The value has no change because the difference is identical between the two guesses (3). The last guess is 13, because we should know that the midpoint would be the

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!