Imagine that the user will write down a positive integer x


Programming in C:

Write a program that will guess an integer that the user has picked. Imagine that the user will write down a positive integer x on a piece of paper and your program will repeatedly ask questions in order to guess what x is, and the user replies honestly. Your program will start by asking for an int n, and you must have 1 = x = n.

After that, the program will successively guess what x is, and the user must tell the computer if x is equal to the guess (entering 'e'), larger than the guess (entering 'l'), or smaller than the guess (entering 's').

Your program will guess by maintaining a lower bound (initially 1) and upper bound (initially n) and pick the largest integer equal to or smaller than1 the midpoint of the lower bound and upper bound.

If the user responds with 'l' indicating that x is larger, the guess becomes the new lower bound plus one. If the user responds with 's' indicating that x is smaller, the guess becomes the new upper bound minus one.

If the user responds with 'e' indicating that x is the guess, your program will report the number of guesses made and terminate execution.

Request for Solution File

Ask an Expert for Answer!!
Computer Engineering: Imagine that the user will write down a positive integer x
Reference No:- TGS02901364

Expected delivery within 24 Hours