Code:
{
if (x== 'n');
printf("Is your number higher or lower?: ");
if (x== 'l')
max = guess;
guess = (min + max) / 2;
printf("Is your number %d?: ", guess);
if (x== 'h');
min = guess;
guess = (min + max) / 2;
printf("Is your number %d?: ", guess);
}
There was your problem. When you're using if statements, you must either make it inline (code all on one line (for issuing one command)) which I do not advise. You must use curly brackets {} for grouping together the parts of each if statement. This code works:
Code:
#include <stdio.h>
#include <stdbool.h>
int main(void)
{
int min = 0;
int max = 100;
int guess;
char x;
guess = (min + max) / 2;
printf("Is your number %d?: ", guess);
while ((x=getchar()) != 'y')
{
if (x== 'n'){
printf("Is your number higher or lower?: ");
}
if (x== 'l'){
max = guess;
guess = (min + max) / 2;
printf("Is your number %d?: ", guess);
}
if (x== 'h'){
min = guess;
guess = (min + max) / 2;
printf("Is your number %d?: ", guess);
}
}
fflush(stdin);
printf("\nPress Enter to continue.");
getchar();
return 0;
}
Have fun, and good luck with C!