标题:新手求助,速回,谢谢
只看楼主
miquan
Rank: 1
等 级:新手上路
帖 子:7
专家分:0
注 册:2008-11-5
结帖率:0
 问题点数:0 回复次数:0 
新手求助,速回,谢谢
#include <stdio.h>
#include <conio.h>
#include <stdlib.h>
#include <ctype.h>
#include <time.h>

#define TURE 1
#define FALSE 0
void main()
{
    
    int       correct = 0;               
    int       number = 0;
    int       success = 0;
    int       i = 0;
    int       shu_chang = 0;
    char      answer = 'Y';
    long  int now = 0;
    long  int seed = 0;
    long    youxi_taken = 0;
    
    printf("\nThis is a memory game,");
    printf(" Enter the number you see");
    printf("\nGood Luck!\ninput y to start\n");
    scanf("%c",&answer);
    
    
    
    
    do
        {
              correct = TURE;              /*用与记录完家输入的正确性*/
              success = 0;                 /*记忆输入的成功次数*/
              shu_chang = 2;
              youxi_taken = clock();       /*记录完家输入的时间*/
              
              while(correct)
              {
                  shu_chang +=success++%3==0;    /*当完家输入3次成功后,记忆长度加1*/
                  seed = time(NULL);             /*生成种子*/
                  
                  now  = clock();                /*记录现在的时间*/
                  
                  srand((int)seed);              /*生成伪随即数字数列*/
                  
                  for(i=1;i<=shu_chang;i++)        /*显示伪随即数字*/
                      printf("%d ",rand()%10);

                  for(;clock()-now<CLOCKS_PER_SEC;);   /*让伪随即数字停留在屏幕上一秒钟*/

                  printf("\r");                        /*让光标回到此行的开头*/

                  for(i=1;i<=shu_chang;i++)            /*输出空格来掩盖显示的随即数字*/
                      printf("  ");

                  if(success==1)                       /*当完家第一次完时,显示次行*/
                       printf("\nPlease enter the number you see\n");
                  
                  else                                 /*第一次以后完时,让光标回到次行开头*/
                     printf("\r");

                  srand((int)seed);                    /*调用第一次电脑生成伪随即数字的种子*/
                      for(i=1;i<=shu_chang;i++)
                      {                                /*把电脑的伪数字和完家输入的数字相比较*/  
                          scanf("%d ",&number);
                      
                          if(number!=rand()%10)
                          {
                              correct = FALSE;         /*当完家输入的数字是错误时候,循环结束*/
                              break;
                          }
                      }

                  printf("%s\n",success?"success!":"wrong!");   /*显示完家输入结果的对错*/
              }
                              

              
                    youxi_taken = (clock()-youxi_taken)/CLOCKS_PER_SEC;    /*计算完家输入数字用的时间*/           

                 printf("\n\nYou score is %d",--success*100/youxi_taken);  /*计算完家的得分*/
                  
                 fflush(stdin);                     /*清理键盘缓存*/
         
            printf("Do you want to continue(y/n)?");   /*问完家是否继续游戏*/
            scanf("%c",&answer);
        
        }while(toupper(answer)=='Y');   /*当完家输入的是Y的时候,游戏继续*/

        getch();
 

}

我输入我看到的数字后还要自己打Y才能继续.
然后他会直接执行while循环外问我继续不,中间的while好象有问题,没有正常执行.

而且他的 shu_chang +=success++%3==0; 每成功输入3次正确长度加一, 没运行
搜索更多相关主题的帖子: correct include success memory number 
2008-11-14 23:40



参与讨论请移步原网站贴子:https://bbs.bccn.net/thread-244317-1-1.html




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

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