标题:+=怎么会这样
只看楼主
FangMengHao
Rank: 1
等 级:新手上路
帖 子:43
专家分:5
注 册:2013-6-19
结帖率:60%
 问题点数:0 回复次数:1 
+=怎么会这样
# include <stdio.h>
# define COVERAGE 200

int main (void)
{
    int sq_feet;
    int cans;

    printf ("Enter number of square feet to be painted: \n");
    while ( scanf("%d", &sq_feet) == 1 )
    {
        cans = sq_feet / COVERAGE;
        cans = cans + ((sq_feet % COVERAGE == 0))? 0: 1;                             // 改成cans += ((sq_feet % COVERAGE == 0))? 0: 1;  则输出就不再是0
                                                                                        为什么?

        printf ("You need %d %s of paint.\n", cans, cans == 1? "can": "cans");
        printf ("Enter next value(q to quit): \n");
    }
    return 0;
}
搜索更多相关主题的帖子: include number Enter 
2014-05-19 21:56
luming10010
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2014-5-19
得分:0 
应该这样就可以啦 cans = cans + ((sq_feet % COVERAGE == 0)? 0: 1);
2014-05-19 22:21



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




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

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