Ive been trying to create a number guessing program were the program guesses your number instead of the user guessing the programs number heres what i have so far:
#include <stdio.h>
int main(void)
{
int guess = 50;
printf("Pick an integer from 1 to 100. I will try to guess ");
printf("it.\nRespond with a y if my guess is right and with");
printf("\nan n if it is wrong.\n");
printf("Uh...is your number %d?\n", guess);
while (getchar() != 'y') /* get response, compare to y */
{
printf("Well, then, is it %d?\n", ++guess);
}
printf("I knew I could do it!\n");
return 0;
}
Now basically all i have to do is modify the program so that it will for ex. say, the
guess is lower, the next guess be halfway between 50 and 100, which is, 75. If that guess is higher, the next guess will be halfway between 75 and 50 which will be 63 since (50 + 75) / 2 = 63. Apparently im supposed to use the binary search strategy. Also i have to allow 1-character response like H or L instead of high or low.
Any Help will be greatly appreciated thanks.