| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 404 人关注过本帖
标题:有一个程序有几个地方看不懂.希望有人能帮我解释一下,
只看楼主 加入收藏
youtk21ai
Rank: 1
等 级:新手上路
帖 子:13
专家分:5
注 册:2010-4-8
结帖率:80%
收藏
已结贴  问题点数:15 回复次数:2 
有一个程序有几个地方看不懂.希望有人能帮我解释一下,
#include "stdio.h"
#include "ctype.h"
#include "stdlib.h"
#include "time.h"

#define TRUE 1
#define FALSE 0

void main(){
    char another_game='Y';
    int correct=FALSE;
    int counter=0;
    int sequence_length=0;
    int i=0;
    long seed=0;
    int number=0;
    long now=0;
    long time_taken=0;
    printf("\nTo play Simple Simon, ");
    printf("watch the screen for a sequence of a 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.");
    printf("\nGood luck !\nPress Enter to play \n");
    scanf("%c",&another_game);
    do
    {
        correct=TRUE;
        counter=0;
        sequence_length=2;
        time_taken=clock();
        while (correct)
        {
            sequence_length+=counter++%3==0;                  \\这个操作后.sequence_length=?运行的时候.感觉好象是3...
            seed=time(NULL);
            now=clock();
            srand((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)                                       \\这里的counter读来读去,感觉一直都等于1.
                printf("\nNow enter the sequence-don't forget the spaces\n");
            else printf("\r");
            srand((int)seed);
            for (i=1;i<sequence_length;i++){
                scanf("%d",&number);
                if(number!=rand()%10)
                {                                                        \\这一段红色的有什么用?感觉有点看不懂.
                    correct=FALSE;
                    break;
                }
            }
            printf("%s",correct?"Correct!":"Wrong!");
        }
        time_taken=(clock()-time_taken)/CLOCKS_PER_SEC;

        printf("\n\nYour 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');
}
搜索更多相关主题的帖子: 解释 
2010-05-01 21:48
youtk21ai
Rank: 1
等 级:新手上路
帖 子:13
专家分:5
注 册:2010-4-8
收藏
得分:0 
怎么没人回我呀?
2010-05-01 22:10
jcslt
Rank: 8Rank: 8
来 自:90-xx.com
等 级:蝙蝠侠
帖 子:251
专家分:975
注 册:2009-10-10
收藏
得分:15 
#include "time.h"
 srand((int)seed);
            for (i=1;i<sequence_length;i++)
            {
                scanf("%d",&number);
                if(number!=rand()%10)//判断你输入的数与随机产生的数是否相等
                {                                                        \\这一段红色的有什么用?感觉有点看不懂.
                    correct=FALSE;//if(FALSE)就是条件不成立
                    break;
                }
            }
            printf("%s",correct?"Correct!":"Wrong!");
用MSDN查下srand函数吧

www.
2010-05-02 18:11
快速回复:有一个程序有几个地方看不懂.希望有人能帮我解释一下,
数据加载中...
 
   



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

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