【C语言编程】航空公司托运行李规定,行李重量不超过10公斤的,托运费按每公斤15元计费

超过的话,超过部分每公斤加收10元。编写一个程序完成计费工作。

#include\x0d\x0aint main()\x0d\x0a{\x0d\x0adouble baggage;\x0d\x0adouble cost;\x0d\x0aprintf("请输入行李的重量:");\x0d\x0ascanf("%lf",&baggage);\x0d\x0aif(baggage>10)\x0d\x0acost=10*15+(baggage-10)*10; \x0d\x0aelse\x0d\x0acost=baggage*15;\x0d\x0aprintf("行李托运费为:cost=%.4lf\n",cost); //精确到小数点后4位\x0d\x0areturn 0;\x0d\x0a\x0d\x0a}
温馨提示:答案为网友推荐,仅供参考
第1个回答  推荐于2019-10-17
#include<stdio.h>
int main()
{
double baggage;
double cost;
printf("请输入行李的重量:");
scanf("%lf",&baggage);
if(baggage>10)
cost=10*15+(baggage-10)*10;
else
cost=baggage*15;
printf("行李托运费为:cost=%.4lf\n",cost); //精确到小数点后4位
return 0;

}本回答被网友采纳
相似回答