是一个猜数的程序,下面是核心代码
int high = 100;
int low = 1;
int guess = (high + low) / 2;
char response;
if (response == 'h')
high = guess - 1;
else if (response == 'l')
low = guess + 1;
guess = (high + low) / 2;
如果别人猜的是大,你的目标数字比别人猜的大,你需要告诉别人大了,然后把大的那个值 = 别人猜的数 - 1,因为他下次猜肯定比这个数小,low是类似的道理。