CSDN首页 空间 新闻 论坛 Blog 下载 读书 网摘 搜索 .NET Java 视频 接项目 求职 在线学习 买书 程序员 通知
山寨机中的战斗机! 程序优化工程师到底对IT界有没有贡献
CSDN社区
搜索 收藏 打印 关闭
CSDN社区 >  C/C++ >  C语言

只不过是一道循环判断的问题,我没做好,方法也不对,能指点一下我的算法错在那里吗?

楼主flashmagic(乱码游魂)2003-05-01 22:34:17 在 C/C++ / C语言 提问

/*题目:企业发放的奖金根据利润提成。利润(I)低于或等于10万元时,奖金可提10%;利润高  
     于10万元,低于20万元时,低于10万元的部分按10%提成,高于10万元的部分,可可提  
     成7.5%;20万到40万之间时,高于20万元的部分,可提成5%;40万到60万之间时高于  
     40万元的部分,可提成3%;60万到100万之间时,高于60万元的部分,可提成1.5%,高于  
     100万元时,超过100万元的部分按1%提成,从键盘输入当月利润I,求应发放奖金总数?  
  */  
   
  #include<iostream>  
  using   namespace   std;  
  main()  
  {  
  float   money;  
  float   itmoney1,itmoney2,itmoney3,itmoney6,itmoney10,itmoney;  
  cout<<"Enter   your   company   this   month's   gain   :   ";  
  cin>>money;  
  if   (0<money&&money<=100000)  
  {  
  itmoney1   =   money*0.1;  
  cout<<"The   conpany's   bonus   of   this   month   is   :   "<<itmoney1<<endl;  
  }  
  else   if(100000<money&&money<=200000)  
  {  
  itmoney2   =   (money-100000)*0.075+100000*0.1;  
  cout<<"The   conpany's   bonus   of   this   month   is   :   "<<itmoney2<<endl;  
  }  
  else   if(200000<money&&money<4000000)  
  {  
  itmoney3   =   (money-200000)*0.05+100000*0.075+100000*0.1;  
  cout<<"The   conpany's   bonus   of   this   month   is   :   "<<itmoney3<<endl;  
  }  
  else   if(400000<money&&money<=600000)  
  {  
  itmoney6   =   (money-400000)*0.03+200000*0.05+100000*0.075+100000*0.1;  
  cout<<itmoney6<<endl;  
  }  
  else   if(600000<money&&money<=1000000)  
  {  
  itmoney10   =   (money-600000)*0.015+200000*0.03+200000*0.05+100000*0.075+100000*0.1;  
  cout<<itmoney10<<endl;  
  }  
  else  
  {  
  itmoney   =   (money-1000000)*0.01+400000*0.015+200000*0.03+200000*0.05+100000*0.075+100000*0.1;  
  cout<<itmoney<<endl;  
  }  
    return   0;  
  } 问题点数:0、回复次数:10Top

1 楼aceboy16(古人)回复于 2003-05-01 22:48:55 得分 0

思路好象没有错,但有一点希望考虑:  
  1、对输入的参数进行显式的数据类型转换“(float)money”且进行数据有效性验证  
  Top

2 楼aviofans(十月风筝)回复于 2003-05-01 23:21:44 得分 0

超过40万之后计算就发生错误,自己仔细再看看啊!我觉得算法没有错的!Top

3 楼flashmagic(乱码游魂)回复于 2003-05-02 16:27:51 得分 0

是这样的!!超过40万后就不对了,具体为什么我也没找出来!!Top

4 楼flashmagic(乱码游魂)回复于 2003-05-02 16:28:58 得分 0

#include<iostream>  
  using   namespace   std;  
  void   main()  
  {  
  float   money1,money2,money4,money6,money10,money;  
  float   itmoney;  
  money1   =   100000*0.1;  
  money2   =   money1   +   100000*0.075;  
  money4   =   money2   +   200000*0.05;  
  money6   =   money4   +   200000*0.03;  
  money10=   money6   +   400000*0.015;  
  cout<<"Enter   your   company   gain   of   this   month   :   ";  
  cin>>itmoney;  
  if(0<itmoney&&itmoney<=100000)  
  money   =   itmoney   *0.1;  
  else   if(100000<itmoney&&itmoney<=200000)  
  money   =   (itmoney-100000)*0.075   +money1;  
  else   if(200000<itmoney&&itmoney<=400000)  
  money   =   (itmoney-200000)*0.05+money2;  
  else   if(400000<itmoney&&itmoney<=600000)  
  money   =   (itmoney-400000)*0.03+money4;  
  else   if(600000<itmoney&&itmoney<=1000000)  
  money   =   (itmoney-600000)*0.015+money6;  
  else   if(1000000<itmoney)  
  money   =   (itmoney-000000)*0.01+money10;  
  cout<<money<<endl;  
  }Top

5 楼tang2003(百无一用)回复于 2003-05-02 16:43:32 得分 0

is   :   "<<itmoney2<<endl;  
  }  
  else   if(200000<money&&money<4000000)  
  这里------------------------------------*Top

6 楼dhfly(飞鸿)回复于 2003-05-02 18:29:31 得分 0

这是潭浩强的C课本上的题,有一本配套题解,可以看一下.Top

7 楼bigtea(企鹅)回复于 2003-05-03 04:28:08 得分 0

else   if(200000<money&&money<4000000)    
  就是这里。Top

8 楼helpall(was jl)回复于 2003-05-03 06:09:20 得分 0

同志们啊,太复杂了吧!       :-)  
  float   getPrize(float   sales)   {  
                  static   float   table[][2]   =   {  
                                  {0,             10.0},  
                                  {100000,     7.5},  
                                  {200000,     5.0},  
                                  {400000,     3.0},  
                                  {600000,     1.5},  
                                  {1000000,   1.0}  
                  };  
                  int   size   =   sizeof(table)/sizeof(float)/2;  
                  float   result   =   0.0;  
                  for(int   i   =   size-1;   i>=   0;   i--)   {  
                                  if(sales   <=   table[i][0])  
                                                  continue;  
                                  result   +=   (sales   -   table[i][0])   *   table[i][1]   /   100.0;  
                                  sales   =   table[i][0];  
                  }  
                  return   result;  
  }Top

9 楼Zark(金陵五月)回复于 2003-05-03 06:11:21 得分 0

又是粗心的老问题了.400000写成4000000了.楼主为什么不能设个断点,自已检查一下呢?  
  Top

10 楼shortppsy(小河)回复于 2003-05-03 08:46:36 得分 0

呵呵:)Top

相关问题

  • 高手指点!语法加亮算法!!
  • 求解算法,敬请各位指点
  • 求一算法,请高人指点
  • 求高手指点1/Z算法
  • 《core java》里两个算法没看懂,哪位指点指点
  • 求助:麻将胡牌判断算法
  • 请行家指点: 关于图形处理算法
  • 图象缩小算法:请高手指点!
  • treeview的高效率算法问题!请大家指点!
  • 一个筛选的算法问题?请指点!!!

关键词

  • itmoney
  • money
  • 提成
  • 高于
  • 部分
  • 利润
  • 奖金
  • 低于
  • float
  • 可提成

得分解答快速导航

  • 帖主:flashmagic

相关链接

  • C/C++ Blog
  • C/C++类图书
  • C/C++类源码下载

广告也精彩

反馈

请通过下述方式给我们反馈
反馈
提问
网站简介|广告服务|VIP资费标准|银行汇款帐号|网站地图|帮助|联系方式|诚聘英才|English|问题报告
北京创新乐知广告有限公司 版权所有, 京 ICP 证 070598 号
世纪乐知(北京)网络技术有限公司 提供技术支持
Copyright © 2000-2008, CSDN.NET, All Rights Reserved
GongshangLogo