Jaunty
2019-10-31 11:12
#include <stdio.h>
int calc_price(float mile, int time)
{
float sum_price;
float per_price = 2.3;
int primary_price = 13;
if(time >= 5 && time < 23)
{
if(mile < 3)
sum_price = primary_price + mile * per_price + 1;
else
sum_price = primary_price + (mile - 3) * per_price + 1;
printf("您在%d点打车,打车费用为%.2f\n", time, sum_price);
}
else
{
if(mile < 3)
sum_price = primary_price + mile * (per_price * 0.2) + 1;
else
sum_price = primary_price + (mile - 3) * (per_price * 0.2) + 1;
printf("您在%d点打车,打车费用为%.2f\n", time, sum_price);
}
return sum_price;
}
int main()
{
printf("打的总费用:%.2f\n",calc_price(12, 9) + calc_price(12, 18));
return 0;
}
你定义了是个整数 int calc_price(float mile, int time),打印printf却是%f;int换成 float试试
C语言入门
926210 学习 · 20797 问题
相似问题