题目:假定邮寄包裹的计费标准如下表,输入包裹重量级邮寄距离,计算出邮兹。
重量/g | 邮资(元/件) |
15 | 5 |
30 | 9 |
45 | 12 |
60 | 14(每满1000km加收1元) |
>=75 | 15(每满1000km加收1元) |
#include <iostream>
using namespace std;
int main()
{
int weight;
int distance;
int fee;
cout<<"请输入包裹的质量和运输的距离"<<"\n";
cin>>weight;
cin>>distance;
if(weight<15){
fee = 5
}
else if(weight<30){
fee = 9;
}
if(weight<45){
fee = 12;
}
else if(weight){
fee = 14 + distance / 1000;
}
else if(weight<75){
fee = 15 + distance / 1000;
}
else
fee = 16 + distance / 1000;
cout<<"所需费用为”<<fee<<endl;
return 0;
}
对于初学的小白来说,养成一个好的写程序方式是特别重要的,就比如说在程序中如果需要用到加减等符号是最好用空格建来将它们分开,这样方便以后在检查程序时更加节省时间。