标题:break的问题
只看楼主
给力小青年
Rank: 1
等 级:新手上路
帖 子:40
专家分:0
注 册:2011-11-20
结帖率:78.57%
已结贴  问题点数:20 回复次数:5 
break的问题
#include "stdafx.h"
#include<stdio.h>
int main(void)
{
    float length, width, c;
    printf("Enter the length of the rectangle: \n");
    while(scanf("%f",&length) )
    {
        printf("Length = %0.2f:\n", length);
        printf("Enter its width: \n");
        if(scanf("%f", &width) != 1)
            break;
        printf("width = %0.2f:\n", width);
        c = length * width;
        printf("Enter the length of 1 the rectangle:\n" );
    }
    printf("Done.\n");
    getchar();
    return 0;
}
为什么不会终止程序
搜索更多相关主题的帖子: include return Enter include return Enter 
2011-12-14 22:18
星火gavin
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:78
专家分:170
注 册:2011-11-5
得分:20 
#include<stdio.h>
int main(void)
{
    float length, width, c;
    printf("Enter the length of the rectangle: \n");
    while(scanf("%f",&length) )
    {
        printf("Length = %0.2f:\n", length);
        printf("Enter its width: \n");
        if(scanf("%.2f", &width) != 1.00)
            break;
        printf("width = %0.2f:\n", width);
        c = length * width;
        printf("Enter the length of 1 the rectangle:\n" );
    }
    printf("Done.\n");
    getchar();
    return 0;
}
注意你定义的是浮点型,if后输出的是浮点数而不是整数1.
还有,试试在if语句中把%f编成%.f(中间加个点)
2011-12-14 22:26
唏嘘草
Rank: 2
等 级:论坛游民
帖 子:128
专家分:93
注 册:2011-6-4
得分:0 
注意那个if里scanf()函数的返回值!
2011-12-14 22:30
gao16forever
Rank: 2
等 级:论坛游民
帖 子:32
专家分:29
注 册:2011-11-29
得分:0 
scanf的返回值是成功读取数据的个数,成功读取了width就不会跳出
2011-12-14 22:30
给力小青年
Rank: 1
等 级:新手上路
帖 子:40
专家分:0
注 册:2011-11-20
得分:0 
回复 2楼 星火gavin
1.00后面改成1.000000   .2f改成f为什么不行  不是默认6位吗?
2011-12-14 22:44
星火gavin
Rank: 3Rank: 3
等 级:论坛游侠
帖 子:78
专家分:170
注 册:2011-11-5
得分:0 
回复 5楼 给力小青年
也许就是因为是默认的吧,给定位数的就没问题,还是确定位数吧,
2011-12-15 22:03



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




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

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