#include"stdio.h"
#include"time.h"
#include"stdlib.h"
void main()
{
clock_t start,over;
double time;
int k=42,a=0;
char ch='a';
start=clock();
scanf("%d",&a);
leap:while(a!=k)
{
if(a>k)
printf("too high");
else
printf("too low");
scanf("%d",&a);
}
printf("答案是%d",k);
k=rand()%100;
scanf("%c",&ch);
if(ch!='n')
goto leap;
over=clock();
time=double(over-start)/CLOCKS_PER_SEC;
printf("总时间=%.0f秒",time);
}按出答案后又会直接进入判断。。。。
按完答案后再按n会进入死循环
你输出答案后 你要在按下n键盘 如果不是的话又一直循环下去的
建议去掉goto语句,用while+break退出
最好不要用goto了,现在goto语句都被淘汰掉了。谭浩强的《C语言程序设计》或者其他C语言的新书里面都有提到。