| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 529 人关注过本帖
标题:帮忙找个错吧,找了老长时间了……(新手,刚入门,,)
只看楼主 加入收藏
wzl963358694
Rank: 2
等 级:论坛游民
帖 子:35
专家分:17
注 册:2013-3-10
结帖率:66.67%
收藏
已结贴  问题点数:12 回复次数:2 
帮忙找个错吧,找了老长时间了……(新手,刚入门,,)
程序代码:
#include <stdio.h>
#include <ctype.h>
#include <stdbool.h>
#include <time.h>
#include <stdlib.h>


int main (void)
{
    char xinyouxi ='Y';                    
    time_t seet =0,                     /*定义种子值*/
           now= 0,                       /*定义游戏时间*/
           now1=0;                       /*记录当前时间*/ 
    int shuzichuan =0;                    /*记录数字串的长度*/ 
    bool zhengque =true;                    /*确定游戏的正确性*/ 
    int cishu = 0;                          /*玩家游戏的次数*/ 
    int shuzi = 0;                      /*游戏玩家输入的数字*/       
           
    printf("这是一个猜数字的游戏!");
    printf("\n每答对三次,难度就会增加!\n");
    printf("按下回车键,进入游戏!\n");
    scanf("%c",&xinyouxi);
    
    do
    {
        zhengque = true ;
        shuzichuan = 2;
        now = clock();
        cishu = 0;
        
        while(zhengque)
        {
            shuzichuan += cishu++ % 3 == 0;          /*确定游戏长度,答对三次后游戏加一位数*/ 
            now1= clock();                    /*记录游戏开始时间*/
            seet= time(NULL);                /*记录当前时间种子值*/
            
            srand((unsigned int)seet);
            for(int i=0 ; i<shuzichuan ; i++)
            printf("%d ", rand() % 10);
            
            for( ; clock()-now1<CLOCKS_PER_SEC ; );
            printf("\r");
            for(int i=0 ; i<shuzichuan ; i++)
            printf("  ");
            
            if(cishu == 1)
            printf("\n请注意输入的格式,数字之间用空格间隔!\n");
            else
            printf("\r");
             
            srand((unsigned int)seet);
            for(int i=0 ; i<shuzichuan ; i++)
                scanf("%d",&shuzi);
                
                if(shuzi == rand() % 10)
                printf("正确!\n");
                else
                {
                    printf("错误!\n");
                    zhengque = false; 
                } 
                
        }
        
        now=(clock()-now)/CLOCKS_PER_SEC;
        printf("你用的时间是%d秒.\n",now);
        
        printf("你答对的次数是%d,成绩是%d\n。",cishu,cishu*10);
       
        printf("是否再玩一次?(y/n):");
        scanf(" %c",&xinyouxi);        
        
        
    }while(toupper(xinyouxi) == 'Y');
    return 0;
}
图片附件: 游客没有浏览图片的权限,请 登录注册
搜索更多相关主题的帖子: 时间 
2013-04-28 03:07
azzbcc
Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19Rank: 19
来 自:江西财经大学
等 级:贵宾
威 望:81
帖 子:3293
专家分:12919
注 册:2012-11-4
收藏
得分:12 
这个,,,

每次判断rand()返回值不一定相同,如何保证输入的是正确的,

另外这个语句没加到循环中,,shuzi变量被覆盖了,只会判断一次

程序代码:
if(shuzi == rand() % 10)
     printf("正确!\n");
else
{
     printf("错误!\n");
     zhengque = false; 
}


[fly]存在即是合理[/fly]
2013-04-28 07:33
wzl963358694
Rank: 2
等 级:论坛游民
帖 子:35
专家分:17
注 册:2013-3-10
收藏
得分:0 
回复 2楼 azzbcc
嗯知道了,,,谢谢
2013-04-28 07:36
快速回复:帮忙找个错吧,找了老长时间了……(新手,刚入门,,)
数据加载中...
 
   



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

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