C语言:快递费用计算
编写一个计算机快递费的程序。
上海市的某快递公司根据投送目的地距离公司的远近,将全国划分成5个区域:

- 快递费按邮件重量计算,由起重费用、续重费用两部分构成:
(1) 起重(首重)1公斤按起重资费计算(不足1公斤,按1公斤计算),超过首重的重量,按公斤(不足1公斤,按1公斤计算)收取续重费;
(2) 同城起重资费10元,续重3元/公斤;
(3) 寄往1区(江浙两省)的邮件,起重资费10元,续重4元;
(4) 寄往其他地区的邮件,起重资费统一为15元。而续重部分,不同区域价格不同:2区的续重5元/公斤,3区的续重6.5元/公斤,4区的续重10元/公斤。
- 提示
续重部分不足一公斤,按1公斤计算。因此,如包裹重量2.3公斤:1公斤算起重,剩余的1.3公斤算续重,不足1公斤按1公斤计算,1.3公斤折合续重为2公斤。如果重量应大于0、区域编号不能超出0-4的范围。
- 输入
用逗号分隔的两个数字,第一个表示区域、第二个是重量:”%d,%f”
- 输出
价格的输出格式:"Price: %.2f\n" 区域错误的提示信息:"Error in Area\n"
#include <stdio.h>
#include <math.h>
int main()
{
int area;
float weight,price = 0;
scanf("%d,%f",&area,&weight);
if(area < 0 || area > 4)
{
printf("Error in Area\n");
}
else if(area == 0)
{
if(weight < 1)
{
price=10;
}
else
{
weight = ceil(weight);
price = 10 + (weight-1)*3;
}
}
else if(area == 1)
{
if(weight < 1)
{
price=10;
}
else
{
weight = ceil(weight);
price = 10 + (weight-1)*4;
}
}
else
{
if(weight < 1)
{
price=15;
}
else
{
if(area == 2)
{
weight = ceil(weight);
price = 15 + (weight-1)*5;
}
else if(area == 3)
{
weight = ceil(weight);
price = 15 + (weight-1)*6.5;
}
else
{
weight = ceil(weight);
price = 15 + (weight-1)*10;
}
}
}
printf("Price: %.2f\n",price);
return 0;
}
6614





