当前位置:   article > 正文

运费计算(C语言)

运费计算(C语言)

一、运行结果;

二、源代码;

  1. # define _CRT_SECURE_NO_WARNINGS
  2. # include <stdio.h>
  3. int main()
  4. {
  5. //初始化变量值;
  6. int distance, c;
  7. float weight, price, discount, fee;
  8. //提示用户;
  9. printf("请输入路程,单价,重量:");
  10. //获取用户输入的值;
  11. scanf("%d %f %f", &distance, &price, &weight);
  12. //判断;
  13. if (distance >= 3000)
  14. {
  15. //改变判断值;
  16. c = 12;
  17. }
  18. else
  19. {
  20. //计算路程区间;
  21. c = distance / 250;
  22. }
  23. //识别区间;
  24. switch (c)
  25. {
  26. case 0:
  27. //确定折扣值;
  28. discount = 0;
  29. break;
  30. case 1:
  31. //确定折扣值;
  32. discount = 2;
  33. break;
  34. case 2:
  35. case 3:
  36. //确定折扣值;
  37. discount = 5;
  38. break;
  39. case 4:
  40. case 5:
  41. case 6:
  42. case 7:
  43. //确定折扣值;
  44. discount = 8;
  45. break;
  46. case 8:
  47. case 9:
  48. case 10:
  49. case 11:
  50. //确定折扣值;
  51. discount = 10;
  52. break;
  53. case 12:
  54. //确定折扣值;
  55. discount = 15;
  56. break;
  57. }
  58. //计算运费;
  59. fee = price * weight * distance * (1 - discount / 100);
  60. //输出结果;
  61. printf("您的货物单价为%.2f元,重量为%.2f千克,运输距离为%d千米,通过计算可得运费为%.2f!!!\n", price, weight, distance, fee);
  62. return 0;
  63. }

三、N-S流程图;

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/从前慢现在也慢/article/detail/473340
推荐阅读
相关标签
  

闽ICP备14008679号