| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1296 人关注过本帖
标题:这个程序为什么不继续往下运行了。。。
只看楼主 加入收藏
wu295653464
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2017-2-13
结帖率:100%
收藏
 问题点数:0 回复次数:9 
这个程序为什么不继续往下运行了。。。
#include <stdio.h>
#include <stdlib.h>
#define ALL_NUMBER_OF_PEOPLE 2
int check(void)
{
    int password;
        printf("*******************\n");
        printf("*请输入4位密码开始游戏*\n");
        printf("*******************\n");
        scanf("%d",&password);
     return password;
}


int outcome(int a,int b)
{
    int time,flat=1;
    int m = 0;
    while(flat)
    {
    scanf("%d %d",&a,&b);
        if(a<10&&b<10){
            m = (a + b)/ALL_NUMBER_OF_PEOPLE;
            flat = 0;
        }
        else{
            printf("输入错误\n");
            time++;
            }
        if (time == 3)
        {
            printf("你输出错误三次了");
            exit(0);
        }
    }
   
    return  m;
   
}


int main(){
    printf("欢迎来到猜数字的游戏! 规则如下:\n");
    printf("游戏需要输入两个一位数,并求平均数\n");
    printf("小数部分会被省略 eg:(4+5)/2 = 4\n");
    printf("那么游戏开始\n");
    int password,i = 0;
     do{
         if (i == 3) {
             printf("你输出错误3次了,游戏结束");
             exit(0);
                }
            password = check();
            i++;
         
        }while(password != 1022);
  
        int a,b,right = 4;
        char n;
        printf("是否需要自定义答案(y/n)\n");
        //fflush(stdin);
        scanf(" %c",&n);
        switch (n)
        {
            case'Y':
            case'y':
                printf("请输入一个一位数数作为答案\n");
                scanf("%d",&right);
                printf("请输入两个零到九的整数\n");
                scanf(" %d %d",&a,&b);
                while(right != outcome(a,b)){
                    if(right - outcome(a,b) > 0)
                    {
                    printf("你输出的太小了\n");
                    }
                    else
                    {
                    printf("你输入的太大了\n");
                    }
                }
            break;
            case'n':
            case'N':
                printf("请输入两个零到九的整数\n");
                while(right != outcome(a,b)){
                    if(right > outcome(a,b))
                    {
                        printf("你输出的太小了\n");
                    }
                    else
                    {
                        printf("你输入的太大了\n");
                    }
            break;
            default:
                    printf("输入有误\n");
            break;
                }
                printf("恭喜你回答正确");
         }
        return 0;
    }

一个猜数字的小代码  我想要加上一个自己设置答案的功能 但是每次运行到“请输入两个零到九的整数”这个位置 我输入完后就没有反映了  程序就停在这里了 这个是什么问题? 编译没错误 不知道需要怎么改。。
搜索更多相关主题的帖子: password 开始游戏 include return 
2017-02-14 13:27
炎天
Rank: 13Rank: 13Rank: 13Rank: 13
来 自:桃花岛
等 级:贵宾
威 望:29
帖 子:1218
专家分:4986
注 册:2016-9-15
收藏
得分:0 
程序代码:
#include <stdio.h>
#include <stdlib.h>
#define ALL_NUMBER_OF_PEOPLE 2
int check(void)
{
    int password;
        printf("*******************\n");
        printf("*请输入4位密码开始游戏*\n");
        printf("*******************\n");
        scanf("%d",&password);
     return password;
}


int outcome(int a,int b)
{
    int time,flat=1;
    int m = 0;
    while(flat)
    {
    
        if(a<10&&b<10){
            m = (a + b)/ALL_NUMBER_OF_PEOPLE;
            flat = 0;
        }
        else{
            printf("输入错误\n");
            time++;
            }
        if (time == 3)
        {
            printf("你输出错误三次了");
            exit(0);
        }
    }
    
    return  m;
    
}


int main(){
    printf("欢迎来到猜数字的游戏! 规则如下:\n");
    printf("游戏需要输入两个一位数,并求平均数\n");
    printf("小数部分会被省略 eg:(4+5)/2 = 4\n");
    printf("那么游戏开始\n");
    int password,i = 0;
     do{
         if (i == 3) {
             printf("你输出错误3次了,游戏结束");
             exit(0);
                }
            password = check();
            i++;
         
        }while(password != 1022);
  
        int a,b,right = 4;
        char n;
        printf("是否需要自定义答案(y/n)\n");
        fflush(stdin);
        scanf("%c",&n);
       
        switch (n)
        {
            case'Y':
            case'y':
                printf("请输入一个一位数数作为答案\n");
                scanf("%d",&right);
                printf("请输入两个零到九的整数\n");
                scanf("%d%d",&a,&b);
                while(right != outcome(a,b)){
                    if(right - outcome(a,b) > 0)
                    {
                    printf("你输出的太小了\n");
                    }
                    else
                    {
                    printf("你输入的太大了\n");
                    }
                     scanf("%d%d",&a,&b);
                }
                   printf("恭喜你回答正确");
            break;
            case'n':
            case'N':
                 printf("请输入两个零到九的整数\n");
                 scanf("%d%d",&a,&b);
                 while(right != outcome(a,b)){
                    if(right > outcome(a,b))
                    {
                        printf("你输出的太小了\n");
                    }
                    else
                    {
                        printf("你输入的太大了\n");
                    }
                    scanf("%d%d",&a,&b);
                }
                    printf("恭喜你回答正确");
            break;
            default:
                    printf("输入有误\n");
            break;
                
         }
        return 0;
    }

早知做人那么辛苦!  当初不应该下凡
2017-02-14 14:28
yangfrancis
Rank: 16Rank: 16Rank: 16Rank: 16
等 级:贵宾
威 望:141
帖 子:1510
专家分:7661
注 册:2014-5-19
收藏
得分:0 
回复 楼主 wu295653464
outcome函数惹的祸
while(right != outcome(a,b)){
                    if(right - outcome(a,b) > 0) //这里怎么会重复输入一次?
                    {
                    printf("你输出的太小了\n");
                    }
                    else
                    {
                    printf("你输入的太大了\n");
                    }
                }
2017-02-14 14:57
wu295653464
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2017-2-13
收藏
得分:0 
回复 3楼 yangfrancis
  呢我应该怎么改这个呢? outcome求的值我应该怎么用到下面的循环里。。
2017-02-14 19:01
姚萌萌
Rank: 2
来 自:湖北
等 级:论坛游民
帖 子:40
专家分:55
注 册:2016-12-25
收藏
得分:0 
nt outcome(int a,int b)
{
    int time,flat=1;
    int m = 0;
    while(flat)
    {
    scanf("%d %d",&a,&b);
        if(a<10&&b<10){
            m = (a + b)/ALL_NUMBER_OF_PEOPLE;
            flat = 0;
        }
        else{
            printf("输入错误\n");
            time++;
            }
        if (time == 3)
        {
            printf("你输出错误三次了");
            exit(0);
        }
    }
   
    return  m;
   
}
这个time没有初始值,你怎么就自加了?
2017-02-15 14:42
绿意盎然
Rank: 2
来 自:湖北
等 级:论坛游民
帖 子:47
专家分:60
注 册:2017-1-5
收藏
得分:0 
学习下
2017-02-15 14:44
姚萌萌
Rank: 2
来 自:湖北
等 级:论坛游民
帖 子:40
专家分:55
注 册:2016-12-25
收藏
得分:0 
#include <stdio.h>
#include <stdlib.h>
#define ALL_NUMBER_OF_PEOPLE 2
#define M 4
int check(void)
{
    int password;
        printf("*******************\n");
        printf("*请输入4位密码开始游戏*\n");
        printf("*******************\n");
        scanf("%d",&password);
     return password;
}


int outcome(int a,int b)
{
    int time=0,flat=1;
    int m = 0;
    while(flat)
    {
        if(a<10&&b<10)
         {
            m = (a + b)/ALL_NUMBER_OF_PEOPLE;
            flat = 0;
        }
        else
        {
            printf("输入错误\n");
            time++;
            printf("请重新输入:\n");
            scanf("%d%d",&a,&b);
        }
        if (time == 3)
        {
            printf("你输出错误三次了");
            exit(0);
        }
    }
   
    return  m;
   
}


int main()
{
    printf("欢迎来到猜数字的游戏! 规则如下:\n");
    printf("游戏需要输入两个一位数,并求平均数\n");
    printf("小数部分会被省略 eg:(4+5)/2 = 4\n");
    printf("那么游戏开始\n");
    int password,i = 0,T=1;
     do
      {
         if (i == 3)
           {
             printf("你输出错误3次了,游戏结束");
             exit(0);
           }
            password = check();
            i++;
         
        }while(password != 1022);
 
     int a,b,right;
     char n;
     printf("是否需要自定义答案(y/n)\n");
     //fflush(stdin);
     scanf("%s",&n);
     while(T)
       {      
        switch (n)
        {
            case'Y':
            case'y':
                printf("请输入一个一位数数作为答案\n");
                scanf("%d",&right);
                printf("请输入两个零到九的整数\n");
                scanf("%d%d",&a,&b);
                if(right != outcome(a,b))
                 {
                    if(right - outcome(a,b) > 0)
                    {
                    printf("你输出的太小了\n");
                    }
                    else
                    {
                    printf("你输入的太大了\n");
                    }
                }
                 else
                 {
                  printf("恭喜你回答正确!");
                 }
              break;
            case'n':
            case'N':
                right=M;
                printf("请输入两个零到九的整数\n");
                scanf("%d%d",&a,&b);
                if(right != outcome(a,b))
                 {
                    if(right-outcome(a,b)>0)
                    {
                        printf("你输出的太小了\n");
                    }
                    else
                    {
                        printf("你输入的太大了\n");
                    }
                  }
                  else
                  {
                   printf("恭喜你回答正确!");
                  }
            break;
            default:
                    printf("输入有误\n");
            break;
        }
        printf("是否继续游戏?(1/是,0/否");
        scanf("%d",&T);
      }
    system("pause");
    return 0;
    }
重新改了一下,我运行没什么问题
2017-02-15 15:24
姚萌萌
Rank: 2
来 自:湖北
等 级:论坛游民
帖 子:40
专家分:55
注 册:2016-12-25
收藏
得分:0 
回复 楼主 wu295653464
#include <stdio.h>
#include <stdlib.h>
#define ALL_NUMBER_OF_PEOPLE 2
#define M 4
int check(void)
{
    int password;
        printf("*******************\n");
        printf("*请输入4位密码开始游戏*\n");
        printf("*******************\n");
        scanf("%d",&password);
     return password;
}


int outcome(int a,int b)
{
    int time=0,flat=1;
    int m = 0;
    while(flat)
    {
        if(a<10&&b<10)
         {
            m = (a + b)/ALL_NUMBER_OF_PEOPLE;
            flat = 0;
        }
        else
        {
            printf("输入错误\n");
            time++;
            printf("请重新输入:\n");
            scanf("%d%d",&a,&b);
        }
        if (time == 3)
        {
            printf("你输出错误三次了");
            exit(0);
        }
    }
   
    return  m;
   
}


int main()
{
    printf("欢迎来到猜数字的游戏! 规则如下:\n");
    printf("游戏需要输入两个一位数,并求平均数\n");
    printf("小数部分会被省略 eg:(4+5)/2 = 4\n");
    printf("那么游戏开始\n");
    int password,i = 0,T=1;
     do
      {
         if (i == 3)
           {
             printf("你输出错误3次了,游戏结束");
             exit(0);
           }
            password = check();
            i++;
         
        }while(password != 1022);
 
     int a,b,right;
     char n;
     printf("是否需要自定义答案(y/n)\n");
     //fflush(stdin);
     scanf("%s",&n);
     while(T)
       {      
        switch (n)
        {
            case'Y':
            case'y':
                printf("请输入一个一位数数作为答案\n");
                scanf("%d",&right);
                printf("请输入两个零到九的整数\n");
                scanf("%d%d",&a,&b);
                if(right != outcome(a,b))
                 {
                    if(right - outcome(a,b) > 0)
                    {
                    printf("你输出的太小了\n");
                    }
                    else
                    {
                    printf("你输入的太大了\n");
                    }
                }
                 else
                 {
                  printf("恭喜你回答正确!");
                 }
              break;
            case'n':
            case'N':
                right=M;
                printf("请输入两个零到九的整数\n");
                scanf("%d%d",&a,&b);
                if(right != outcome(a,b))
                 {
                    if(right-outcome(a,b)>0)
                    {
                        printf("你输出的太小了\n");
                    }
                    else
                    {
                        printf("你输入的太大了\n");
                    }
                  }
                  else
                  {
                   printf("恭喜你回答正确!");
                  }
            break;
            default:
                    printf("输入有误\n");
            break;
        }
        printf("是否继续游戏?(1/是,0/否");
        scanf("%d",&T);
      }
    system("pause");
    return 0;
    }
重新改了一下,我运行没什么问题
2017-02-15 15:28
wu295653464
Rank: 1
等 级:新手上路
帖 子:4
专家分:0
注 册:2017-2-13
收藏
得分:0 
回复 8楼 姚萌萌
哭瞎了 我给time付了初始值 也运行不下去。。。
2017-02-16 11:28
姚萌萌
Rank: 2
来 自:湖北
等 级:论坛游民
帖 子:40
专家分:55
注 册:2016-12-25
收藏
得分:0 
回复 9楼 wu295653464

    int time,flat=1;
    int m = 0;
    while(flat)
    {
    scanf("%d %d",&a,&b);
        if(a<10&&b<10){
           还有这里,为什么有输入a,b的,不是用形参传递过来了吗?为什么还要输入
2017-02-16 22:25
快速回复:这个程序为什么不继续往下运行了。。。
数据加载中...
 
   



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

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