I see, thanks for you guys to help me, sorry for the bad indentation, I should improve on that also.
I did a review of my code, and came out the code here:
Code:
#include<stdio.h>
int main(void)
{
int a;
char response;
printf("pls pick up a no from 1 to 100:");
printf("is your no 50?");
if((response=getchar())=='l')
{
printf("%c",response);
a=75;
printf("is your no %d",a);
while(getchar()!='\n')
continue;
while((response=getchar())!='y')
{
if(response=='h')
{
a=50+(a-50)/2;
printf("is your no %d",a);
while(getchar()!='\n')
continue;
}
else
{
a=a+(100-a)/2;
printf("%c",response);
printf("is your no %d",a);
while(getchar()!='\n')
continue;
}
}
printf("I got it,haha!");
}
else if((response=getchar())=='h')
{
a=25;
printf("is your no %d",a);
while(getchar()!='\n')
continue;
while((response=getchar())!='y')
{
if(response=='h')
{
a=(a-1)/2;
printf("is your no %d",a);
while(getchar()!='\n')
continue;
}
else
{
a=a+(50-a)/2;
printf("is your no %d",a);
while(getchar()!='\n')
continue;
}
}
printf("I got it,haha!");
}
else
printf("I got it, haha!");
system("pause");
return 0;
}
it is working when I first gave the answer "low". but it gives me "I got it, haha!" after I keyed in "high"(it should take a guess of 25 instead).
I cannot find anything wrong with the conditonal statements