这是我的程序:
#include<stdio.h>
#include<ctype.h>
#include<stdbool.h>
#include<stdlib.h>
#include<time.h>
int main(void)
{char another_game='Y';
int correct=false;
int counter=0;
int sequence_length=0;
time_t seed=0;
int number=0;
time_t now=0;
int time_taken=0;
int i;
printf("来玩西蒙游戏\n");
printf("请仔细观看屏幕\n");
printf("一次机会\n");
printf("祝你好运,请输入:\n");
scanf("%c",&another_game);
do{correct=true;
counter=0;
sequence_length=2;
time_taken=clock();
while(correct)
{
sequence_length += counter++%3 == 0;
seed=time(NULL)
now=clock();
srand((unsigned int)seed);
for(i=1;i<=sequence_length;i++)
printf("%d",rand()%10);
for(;clock() - now < CLOCKS_PER_SEC;);
printf("\r");
for(i=1;i<=sequence_length;i++)
printf(" ");
if(counter == 1)
printf("请输入:\n");
else
printf("\r");
srand((unsigned int)seed);
for(i=1;i<=sequence_length;i++)
{
scanf("%d",&number);
if(number !=rand() % 10)
{
correct=false;
break;
}
}
printf("%s\n",correct?"正确!":"错误!");
}
time_taken=(clock()-time_taken) / CLOCKS_PER_SEC;
printf("\n\n你的得分是%d",--counter * 100 / time_taken);
fflush(stdin);
printf("\n你想继续玩吗 (y/n)?");
scanf("%c",&another_game);
}
while(toupper(another_game)=='Y');
return 0;
}
#include<stdio.h>
#include<ctype.h>
#include<stdbool.h>
#include<stdlib.h>
#include<time.h>
int main(void)
{char another_game='Y';
int correct=false;
int counter=0;
int sequence_length=0;
time_t seed=0;
int number=0;
time_t now=0;
int time_taken=0;
int i;
printf("来玩西蒙游戏\n");
printf("请仔细观看屏幕\n");
printf("一次机会\n");
printf("祝你好运,请输入:\n");
scanf("%c",&another_game);
do{correct=true;
counter=0;
sequence_length=2;
time_taken=clock();
while(correct)
{
sequence_length += counter++%3 == 0;
seed=time(NULL)
now=clock();
srand((unsigned int)seed);
for(i=1;i<=sequence_length;i++)
printf("%d",rand()%10);
for(;clock() - now < CLOCKS_PER_SEC;);
printf("\r");
for(i=1;i<=sequence_length;i++)
printf(" ");
if(counter == 1)
printf("请输入:\n");
else
printf("\r");
srand((unsigned int)seed);
for(i=1;i<=sequence_length;i++)
{
scanf("%d",&number);
if(number !=rand() % 10)
{
correct=false;
break;
}
}
printf("%s\n",correct?"正确!":"错误!");
}
time_taken=(clock()-time_taken) / CLOCKS_PER_SEC;
printf("\n\n你的得分是%d",--counter * 100 / time_taken);
fflush(stdin);
printf("\n你想继续玩吗 (y/n)?");
scanf("%c",&another_game);
}
while(toupper(another_game)=='Y');
return 0;
}