#include<stdio.h>
#include<time.h>
#include<stdlib.h>
char p;
void caishu(void)
{
int m,n;
srand(time(NULL));
m=rand()%1000+1;
printf("I havu a number between 1 and 1000.\nCan you guess my number.\nPlease type your frist guess.\n");
scanf("%d",&n);
while(n!=m){
if(n>m){
printf("Too high.Try again.\n");
scanf("%d",&n);
}
if(n<m){
printf("Too low.Try again.\n");
scanf("%d",&n);
}
}
printf("Excellent!You guessed the number!\nWould you like to play again?( y or n ):");
scanf("%c",&p);/*就是这里了,总是自动读取了最后一个正确答案的回车,而不是等待输入*/
}
main()
{
caishu();
while(p=='y'){
caishu();
}
if(p=='n')
printf("Byebye");
while(p!='y'&&p!='n'){
printf("Wrong order\n");
printf("Would you play again?( y or n ):");
scanf("%c",&p);
while(p=='y'){
caishu();
}
if(p=='n')
printf("Byebye");
}
return 0;
}
[此贴子已经被作者于2007-3-28 21:14:31编辑过]