该楼层疑似违规已被系统折叠 隐藏此楼查看此楼
# include
# include
# include
# include
# include int main(void)
{
char another_game = 'Y';
int correct = false;
int counter = 0;
int length = 0;
time_t seed = 0;
int number = 0;
time_t now = 0;
int time_taken = 0;
printf("\nTo play Simple Simon, ");
printf("watch the screen for a sequence of digits. ");
printf("\nWatch carefully, as the digits are only displayed"
" for a second! ");
printf("The computer will remove them, and then prompt you ");
printf("to enter the same sepuence.");
printf("\n When you do, you must put sapces between the digits. \n");
printf("\n Good Luck! \n Press Enter to play\n");
scanf("%c", &another_game);
do
{
correct = true;
counter = 0;
length = 2;
time_taken = clock();
while(correct)
{
length +=counter++%3 == 0;
seed = time(NULL);/**/
now = clock();/**/
srand((unsigned int)seed);/**/
for (int i = 1; i < length; i++)
printf("%d", rand() % 10);
for ( ; clock() - now < CLOCKS_PER_SEC; )
;
printf("\r");
printf("\t\r\t");
for(int i = 1; i < length; i++)
{
if (counter == 1)
printf("\n Now you enter the sequence - don't"
" forget the spaces\n");
else
printf("\r");
}
srand((unsigned int )seed);
for(int i = 1; i < length; i++)
{
scanf("%d", &number);
if (number != rand() % 10)
{
correct = false;
break;
}
}
printf("%s\n", correct ? "Correct!" : "Wrong!");
}
time_taken = (clock() - time_taken) / CLOCKS_PER_SEC;
printf("\n\n Your score is %d", --counter * 100 / time_taken);
fflush(stdin);
printf("\nDo you want to play again (y/n)? : ");
scanf("%c", &another_game);
} while(toupper (another_game) == 'Y');
return 0;
}