請問為什么是69.40002?
#include <stdio.h>
float taxicost(int time,int dis)
{
? ? ? ? float result;
? ? ? ? if(dis<=3)
? ? ? ? {
? ? ? ? ? ? result=14;
? ? ? ? }
? ? ? ? else if(time<5||time>=23)
? ? ? ? {
? ? ? ? ? ? result=14+2.3*1.2*(dis-3);
? ? ? ? }
? ? ? ? else
? ? ? ? {
? ? ? ? result=14+2.3*(dis-3);
? ?}?
return result;?
}
? ? int main()
? ? {
? ? printf("小明每天打車的總費用為%f\n元",taxicost(9,12)+taxicost(18,12));
? ? return 0;
} ?
2016-11-15
因為你設(shè)的費用是單精度的,所以有小數(shù)點啊,而且數(shù)據(jù)的不確定性(專業(yè)術(shù)語我想不起來了),零后面會帶2,除了.1f,還可以用%g,%g是在科學(xué)計數(shù)法和普通方法之間自動選擇最短的形式輸出.你可以試一下。望采納