赞
踩
一、运行结果;
二、源代码;
- # define _CRT_SECURE_NO_WARNINGS
- # include <stdio.h>
-
- int main()
- {
- //初始化变量值;
- int distance, c;
- float weight, price, discount, fee;
-
- //提示用户;
- printf("请输入路程,单价,重量:");
- //获取用户输入的值;
- scanf("%d %f %f", &distance, &price, &weight);
-
- //判断;
- if (distance >= 3000)
- {
- //改变判断值;
- c = 12;
- }
- else
- {
- //计算路程区间;
- c = distance / 250;
- }
-
- //识别区间;
- switch (c)
- {
- case 0:
- //确定折扣值;
- discount = 0;
- break;
- case 1:
- //确定折扣值;
- discount = 2;
- break;
- case 2:
- case 3:
- //确定折扣值;
- discount = 5;
- break;
- case 4:
- case 5:
- case 6:
- case 7:
- //确定折扣值;
- discount = 8;
- break;
- case 8:
- case 9:
- case 10:
- case 11:
- //确定折扣值;
- discount = 10;
- break;
- case 12:
- //确定折扣值;
- discount = 15;
- break;
-
- }
-
- //计算运费;
- fee = price * weight * distance * (1 - discount / 100);
-
- //输出结果;
- printf("您的货物单价为%.2f元,重量为%.2f千克,运输距离为%d千米,通过计算可得运费为%.2f!!!\n", price, weight, distance, fee);
-
- return 0;
- }
三、N-S流程图;
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。