C++ 如何使用时间函数(一)

2013-02-08 14:30:55 · 作者: · 浏览: 613

  这里提供一个 记忆游戏 类似于记单词

  #include <stdio.h>                     /* For input and output   */

  #include <ctype.h>                     /* For toupper() function */

  //#include <stdbool.h>                   /* For bool, true, false  */

  #include <stdlib.h>                    /* For rand() and srand() */

  #include <time.h>                      /* For time() and clock() */

  int main(void)

  {

  /* Records if another game is to be played */

  char another_game = 'Y';

  /* true if correct sequence entered, false otherwise */

  int correct = false;

  /* Number of sequences entered successfully          */

  int counter = 0;

  int sequence_length = 0;     /* Number of digits in a sequence        */

  time_t seed = 0;             /* Seed value for random number sequence */

  int number = 0;              /* Stores an input digit                 */

  time_t now = 0;            /* Stores current time - seed for random values  */

  int time_taken = 0;        /* Time taken for game in seconds                */

  /* Describe how the game is played */

  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("\nThe computer will remove them, and then prompt you ");

  printf("to enter the same sequence.");

  printf("\nWhen you do, you must put spaces between the digits. \n");

  printf("\nGood Luck!\nPress Enter to play\n");

  scanf("%c", &another_game);

  /* One outer loop iteration is one game */