猜字游戏c语言程序,C语言 猜字游戏

#include

#include

#include

#include

main()

{

char c;

clock_t start, end;

time_t a, b;

double var;

int i, guess;

int YY;

srand(time(NULL));

printf("do you want to play it.('y' or 'n') \n");

loop:

while((c=getchar()) == 'y')

{

i = rand()%100;

YY = 1;

printf("\nPlease input number you guess:\n");

start = clock();

a = time(NULL);

scanf("%d", &guess);

while(guess!=i)

{

printf("%d %c\n", guess, guess);

if(guess>i)

{

printf("please input a little smaller.\n");

if(!scanf("%d", &guess)){YY = 0;break;};

}

else

{

printf("please input a little bigger.\n");

if(!scanf("%d", &guess)){YY = 0;break;};

}

}

end = clock();

b = time(NULL);

printf("\1: It took you %6.3f seconds\n", var=(double)(end-start)/1000);

printf("\1: It took you %6.3f seconds\n\n", difftime(b, a));

if(YY == 0)

{

printf("input data type error!");

}

else if(var < 15 && YY == 1)

{

printf("\1\1 You are vary clever! \1\1\n\n");

}

else if(var < 25 && YY == 1)

{

printf("\1\1 you are normal! \1\1\n\n");

}

else

{

printf("\1\1 you are stupid!\1\1\n\n");

}

if(YY == 1)

{

printf("The number you guess is %d", i);

}

}

printf("\nDo you want to try t again?(\"y\".or.\"n\")\n");

if((c=getch()) == 'y')

goto loop;

}

//对数据进行简单的异常处理

你可能感兴趣的:(猜字游戏c语言程序)