| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1235 人关注过本帖
标题:比较两数大小,在循环内为何不能继续执行比较
只看楼主 加入收藏
南山浅悠然
Rank: 2
等 级:论坛游民
威 望:1
帖 子:53
专家分:92
注 册:2014-5-21
结帖率:100%
收藏
已结贴  问题点数:10 回复次数:5 
比较两数大小,在循环内为何不能继续执行比较

只能比较一次,比较完之后直接退出。。。。。。

#include <stdio.h>
#include <ctype.h>

int main(void)
{
    int num1 = 0;
    int num2 = 0;
    char judge;
   
    do
    {
        puts ("Enter the two numbers.");
        scanf ("%d%d", &num1, &num2);
        
        if ( num1 > num2)
            printf ("\n%d greather than %d", num1, num2);
        else
            printf ("%d less than %d\n", num1, num2);
            
        puts ("Whether to continue?");
        scanf ("%c", &judge);
      
    }while(tolower(judge) == 'y');
   

    return 0;
}
搜索更多相关主题的帖子: continue include numbers Enter 
2016-11-01 15:52
wp231957
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:神界
等 级:贵宾
威 望:423
帖 子:13688
专家分:53332
注 册:2012-10-18
收藏
得分:10 
2条scanf之间不能直通  中间需要添加清除缓冲区的语句
收到的鲜花
  • 炎天2016-11-01 16:04 送鲜花  6朵   附言:我很赞同

DO IT YOURSELF !
2016-11-01 15:57
南山浅悠然
Rank: 2
等 级:论坛游民
威 望:1
帖 子:53
专家分:92
注 册:2014-5-21
收藏
得分:0 
回复 2楼 wp231957
我在第一个scanf后面添加了一条语句fflush(stdin);但没用啊
2016-11-01 16:38
wp231957
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:神界
等 级:贵宾
威 望:423
帖 子:13688
专家分:53332
注 册:2012-10-18
收藏
得分:0 
回复 3楼 南山浅悠然
没有问题啊
程序代码:
Enter the two numbers.
5 8
5 less than 8
Whether to continue?
y
Enter the two numbers.
8 5

8 greather than 5
Whether to continue?
y
Enter the two numbers.
5 5
5 less than 5
Whether to continue?
y
Enter the two numbers.
0 89
0 less than 89
Whether to continue?
y
Enter the two numbers.
89 52

89 greather than 52
Whether to continue?



DO IT YOURSELF !
2016-11-02 08:36
wp231957
Rank: 20Rank: 20Rank: 20Rank: 20Rank: 20
来 自:神界
等 级:贵宾
威 望:423
帖 子:13688
专家分:53332
注 册:2012-10-18
收藏
得分:0 
程序代码:
#include <stdio.h>
#include <ctype.h>

int main(void)
{
    int num1 = 0;
    int num2 = 0;
    char judge;
    
    do
    {
        puts ("Enter the two numbers.");
        scanf ("%d%d", &num1, &num2);
        
        if ( num1 > num2)
            printf ("\n%d greather than %d\n", num1, num2);
        else
            printf ("%d less than %d\n", num1, num2);
            
        puts ("Whether to continue?");
        fflush(stdin);
        scanf ("%c", &judge);
       
    }while(tolower(judge) == 'y');
    

    return 0;
}

DO IT YOURSELF !
2016-11-02 08:36
南山浅悠然
Rank: 2
等 级:论坛游民
威 望:1
帖 子:53
专家分:92
注 册:2014-5-21
收藏
得分:0 
回复 4楼 wp231957
汗😓,手机编译器有问题,多谢了
2016-11-08 10:19
快速回复:比较两数大小,在循环内为何不能继续执行比较
数据加载中...
 
   



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

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