| 网站首页 | 业界新闻 | 小组 | 威客 | 人才 | 下载频道 | 博客 | 代码贴 | 在线编程 | 编程论坛
欢迎加入我们,一同切磋技术
用户名:   
 
密 码:  
共有 1018 人关注过本帖, 1 人收藏
标题:我编的一个奖金取得程序,为什么不论怎么输入都是没有奖金呢?
只看楼主 加入收藏
xinyuanyuan
Rank: 2
等 级:论坛游民
帖 子:12
专家分:10
注 册:2012-2-14
收藏
得分:0 
这个程序执行效率太低,每一个奖金都得重复计算多次,可以改进。输入格式的错误,这个不算讨论的范畴,可能是作者笔误。
2012-02-14 12:30
kenrual
Rank: 1
等 级:新手上路
帖 子:1
专家分:0
注 册:2012-2-14
收藏
得分:0 
以下是引用chihuyu在2012-2-13 20:43:37的发言:

#include"stdio.h"
#include"math.h"
void main()
{
    double profit,bonus;
    scanf("%f",&profit);
    if(profit<=0)
    {
        printf("今年没有奖金!\n");
    }
    else
    {
        if(profit<=10)
        {
            bonus=profit*10.0/100;
        }
        else if(profit<=20)
        {
            bonus=10*10.0/100+(profit-10)*7.5/100;
        }
        else if(profit<=40)
        {
            bonus=10*10.0/100+10*7.5/100+(profit-20)*5.0/100;
        }
        else if(profit<=60)
        {
            bonus=10*10.0/100+10*7.5/100+20*5.0/100+(profit-40)*3.0/100;
        }
        else if(profit<=100)
        {
            bonus=10*10.0/100+10*7.5/100+20*5.0/100+20*3.0/100+(profit-60)*1.5/100;
        }
        else
        {
            bonus=10*10.0/100+10*7.5/100+20*5.0/100+20*3.0/100+40*1.5/100+(profit-100)*1.0/100;
        }

        printf("今年的奖金是%g\n",bonus);

    }
}


还是用case吧,这么多if不好
2012-02-14 14:55
快速回复:我编的一个奖金取得程序,为什么不论怎么输入都是没有奖金呢?
数据加载中...
 
   



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

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