[分享] 用C语言做个一个小游戏
一个猜数字的游戏,游戏的规则很简单:任意输入一个数之后,系统将提示你猜的数是大了,还是小了,根据所用时间来判断你的IQ #include "time.h"
#include "stdio.h"
#include "stdlib.h"
main()
{char c; clock_t start,end;
time_t a,b;
double var; int i,guess;
srand(time(NULL));
printf("do you wnat to play it.('y'or 'n')\n");
loop:
while((c=getch())=='y')
{i=rand()%100;
printf("\n please input number you guess:\n");
start=clock();
a=time(NULL);
scanf("%d",&guess);
while (guess!=i)
{if (guess>i)
{printf("please input a little smaller.\n");
scanf("%d",&guess);}
else
{printf(" plese input a little bigger .\n");
scanf("%d",&guess);}
}end=clock();
b=time(NULL);
printf("\1: It take you %6.3f seconds\n",var=(double)(end-start)/1.82);
printf("\1: It took you %6.3f seconds\n",difftime(b,a));
if (var<15)
printf("\1\1 You are very clever!\1\1\n"); else if (var>25)
printf("\1\1 you are normal!\1\1\n\n");
else
printf("\1\1 you are stupid!\1\1\n\n");
printf("\1\1 congralations \1\1\n\n");
printf("The number you guess is %d",i);
}
printf ("\n do you want to try it again ? (\"y\",or \"n\")\n");
if ((c=getch())=='y')
goto loop;
}