為什么sum加不起來,請教大神!
#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;
}
2019-11-01
你定義了是個整數(shù) int calc_price(float mile, int time),打印printf卻是%f;int換成 float試試