本题的switch语句解法,比较麻烦可以了解一下

  1. #include<iostream>
  2. #include<iomanip>
  3. using namespace std;
  4. int main() {
  5. cout<<fixed<<setprecision(2);
  6. double profit=0;
  7. double bonus,sum=0;
  8. int c;
  9. cin>>profit;
  10. c=profit/100000;
  11. if(c>=0)
  12. switch(c) {
  13. case 0:
  14. bonus=profit*0.1;
  15. cout<<bonus<<endl;
  16. break;
  17. case 1:
  18. bonus=10*10000*0.1+(profit-10*10000)*0.075;
  19. cout<<bonus<<endl;
  20. break;
  21. case 2:
  22. bonus=10*10000*0.175+(profit-20*10000)*0.05;
  23. cout<<bonus<<endl;
  24. break;
  25. case 3:
  26. bonus=10*10000*0.175+(profit-20*10000)*0.05;
  27. cout<<bonus<<endl;
  28. break;
  29. case 4:
  30. bonus=10*10000*0.175+20*10000*0.05+(profit-40*10000)*0.03;
  31. cout<<bonus<<endl;
  32. break;
  33. case 5:
  34. bonus=10*10000*0.175+20*10000*0.05+(profit-40*10000)*0.03;
  35. cout<<bonus<<endl;
  36. break;
  37. case 6:
  38. bonus=10*10000*0.175+20*10000*0.05+20*10000*0.03+(profit-60*10000)*0.015;
  39. cout<<bonus<<endl;
  40. break;
  41. case 7:
  42. bonus=10*10000*0.175+20*10000*0.05+20*10000*0.03+(profit-60*10000)*0.015;
  43. cout<<bonus<<endl;
  44. break;
  45. case 8:
  46. bonus=10*10000*0.175+20*10000*0.05+20*10000*0.03+(profit-60*10000)*0.015;
  47. cout<<bonus<<endl;
  48. break;
  49. case 9:
  50. bonus=10*10000*0.175+20*10000*0.05+20*10000*0.03+(profit-60*10000)*0.015;
  51. cout<<bonus<<endl;
  52. break;
  53. case 10:
  54. bonus=10*10000*0.175+20*10000*0.05+20*10000*0.03+40*10000*0.015+(profit-100*10000)*0.01;
  55. cout<<bonus<<endl;
  56. break;
  57. default:
  58. bonus=10*10000*0.175+20*10000*0.05+20*10000*0.03+40*10000*0.015+(profit-100*10000)*0.01;
  59. cout<<bonus<<endl;
  60. break;
  61. }
  62. return 0;
  63. }
点赞(0)
 

8 分

1 人评分

 

C语言网提供由在职研发工程师或ACM蓝桥杯竞赛优秀选手录制的视频教程,并配有习题和答疑,点击了解:

一点编程也不会写的:零基础C语言学练课程

解决困扰你多年的C语言疑难杂症特性的C语言进阶课程

从零到写出一个爬虫的Python编程课程

只会语法写不出代码?手把手带你写100个编程真题的编程百练课程

信息学奥赛或C++选手的 必学C++课程

蓝桥杯ACM、信息学奥赛的必学课程:算法竞赛课入门课程

手把手讲解近五年真题的蓝桥杯辅导课程

评论列表 共有 0 条评论

暂无评论