| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 534 人关注过本帖
标题:关于C的记忆数字游戏,请大神指出其错误,编译错误
只看楼主 加入收藏
cc786857257
Rank: 1
等 级:新手上路
帖 子:15
专家分:6
注 册:2013-8-18
结帖率:50%
收藏
 问题点数:0 回复次数:0 
关于C的记忆数字游戏,请大神指出其错误,编译错误
#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 i=1;
   int sequence_length=0;

   time_t seed=0;
   int number=0;
 
   time_t now=0;
   int time_taken=0;
 

printf("\n To play simple simon");
printf("\n watch the screen for a sequence of digits.");
printf("\nwatch carefully, as the digitsare only displayed");
printf(",,,,,,");
printf(",,,,,,");
printf(",,,,,,");
printf(",,,,,,");

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 ;i <=sequence_length;i++)
      printf("%d",rand() % 10);
 
   for(;clock()-now<CLOCKS_PER_SEC;);
      printf("\r");

   for(i;i<=sequence_length;i++)
      printf(" ");


   if(counter==1)
        printf("\n Now you enter the seqence-don't forget"
    "the spaces\n");
    else
         printf("\r");


    srand((unsigned int)seed);
    for(i;i <=sequence_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;
}
搜索更多相关主题的帖子: carefully sequence correct counter include 
2013-08-31 07:27
快速回复:关于C的记忆数字游戏,请大神指出其错误,编译错误
数据加载中...
 
   



关于我们 | 广告合作 | 编程中国 | 清除Cookies | TOP | 手机版

编程中国 版权所有,并保留所有权利。
Powered by Discuz, Processed in 0.028665 second(s), 7 queries.
Copyright©2004-2024, BCCN.NET, All Rights Reserved