Open sq4250 opened 1 year ago
加了一行
while(getchar()!='\n');
清除缓存
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
char str[3];int m;
int main(){
do{
srand((unsigned)time(NULL));
int n=rand()%1000;int i=1;
printf("Type a number up to 1000:");
scanf("%d",&m);
while(m!=n)
{
if (m>n) printf("Too big!\nType a number up to 1000:");
else if(m<n) printf("Too small!\nType a number up to 1000:");
while(getchar()!='\n');
scanf("%d",&m);
i++;
}
while(getchar()!='\n');
printf("Congratulation!(%d times)\n",i);
printf("NEW GAME?(y/n):");
gets(str);
}while (str[0]=='y');
return 0;
}
#include<stdio.h>
#include<stdlib.h>
#include<time.h>
char str[3];int m;
int main(){
do{
srand((unsigned)time(NULL));
int n=rand()%1000;
int i=0;
do{
printf("Type a number up to 1000:");
scanf("%d",&m);
if (m>n) printf("Too big!\n");
else if(m<n) printf("Too small!\n");
i++;
while(getchar()!='\n');
}while(m!=n);
printf("Congratulation!(%d times)\n",i);
printf("NEW GAME?(y/n):");
gets(str);
}while (str[0]=='y');
return 0;
}
wuuuuuu~~~
当我键入数字时一切安好 然后就死循环了,当我键入数字以外的符号时23333 代码: