猜数游戏
#include<stdio.h>#include<stdlib.h>
#include<time.h>/*头文件*/
void main()
{
int ia,ib;
long ic;
char ca,cb,cc;
time_t beg,end; /*定义时间变量*/
printf("Do you want to play this game?('y' or 'n')\n");
ca=getchar();
while(ca!='n') /*循环*/
{
ia=rand(100); /*产生随机数*/
printf("Now the system have produced a random number between 0 to 99,enter your guess:\n");
scanf("%d",&ib);
time(&beg); /*获取当前时间*/
while(ib!=ia)
{
if(ib>ia)
{
printf("please input a smaller number!\n");
}
if(ib<ia)
{
printf("please input a bigger number!\n");
}
scanf("%d",&ib);
}
time(&end); /*获取结束时间*/
ic=end-beg; /*计算所花时间*/
printf("Success!It took you %ld seconds to finish\n",ic);
{
if(ic<15)
{
printf("you are clever!\n");
}
else if(ic<25)
{
printf("you are normal!\n");
}
else
{
printf("you are stupid!\n");
}
}
getchar();
printf("Do you want to play this game?('y' or 'n')\n");
scanf("%c",&ca);
}
}
这是个猜数的程序,可是为什么正确一次后想要再次游戏,不管输入什么数字,程序总是输出“please input a bigger number!” ???