见过一个类似的猜数游戏,但是程序可能有问题,怎么猜都是猜的太慢,别的没什么问题。
#include“time.h“
#include“stdlib.h“
#include“stdio.h“
main()
{charc;
clock_tstart,end;
time_ta,b;
doublevar;
inti,guess;
srand(time(NULL));
printf(“doyouwanttoplayit.(’y’or’n’)\n“);
loop:
while((c=getchar())==’y’)
{
i=rand()%100;
printf(“\npleaseinputnumberyouguess:\n“);
start=clock();
a=time(NULL);
scanf(“%d“,&guess);
while(guess!=i)
{if(guess〉i)
{printf(“pleaseinputalittlesmaller.\n“);
scanf(“%d“,&guess);}
else
{printf(“pleaseinputalittlebigger.\n“);
scanf(“%d“,&guess);}
}
end=clock();
b=time(NULL);
printf(“\1:Ittookyou%6.3fseconds\n“,var=(double)(end-start)/18.2);
printf(“\1:ittookyou%6.3fseconds\n\n“,difftime(b,a));
if(var〈15)
printf(“\1\1Youareveryclever!\1\1\n\n“);
elseif(var〈25)
printf(“\1\1youarenormal!\1\1\n\n“);
else
printf(“\1\1youarestupid!\1\1\n\n“);
printf(“\1\1Congradulations\1\1\n\n“);
printf(“Thenumberyouguessis%d“,i);
}
printf(“\ndoyouwanttotryitagain?(\“yy\“.or.\“n\“)\n“);
if((c=getch())==’y’)
gotoloop;
}