我的答案是69.400002,求大神忙我看看
#include?<stdio.h> float?str(i,j) { ????float?n; ????if(i<=3) ????n=14; ????else?if(j>=23||j<=5) ????n=14+(i-3)*2.3*1.2; ????else ????n=14+(i-3)*2.3; ????return?n; ????} int?main() { ????printf("小明每天打車費(fèi)用為%f",str(12,9)+str(12,18)); ????return?0; }
2016-04-01
#include <stdio.h>
double getTaxiPrice(int hours,int distance)
{
?double totalPrice = 0.0;?//定義打車費(fèi)用
?double perPrice = 2.3;?//定義每公里單價(jià)計(jì)費(fèi)
?int startPrice = 13;?//定義起步價(jià)
?if(hours<0 || hours>24){
??printf("請?zhí)顚懻_的時(shí)間\n");
??return 0;
?}
?else if(!(hours>=5 && hours<23))?//判斷打車時(shí)間是否要增加費(fèi)用
?{
??perPrice *= 1.2;?//費(fèi)用增加20%????????????????????????
?}
?if(distance >3)??//判斷公里數(shù)
?{
??totalPrice = startPrice +(distance - 3)*perPrice;?//計(jì)算價(jià)錢
?}
?else
?{
??totalPrice = startPrice;???
?}
?totalPrice++;?//加一塊錢的燃油費(fèi)
?return totalPrice;
}
int main()
{
?int moring = 9;?//定義上午打車時(shí)間
?int afternoon = 18;?//定義下午打車時(shí)間
?int distance = 12;?//定義打車公里數(shù)
?double totalPrice = 0;?//定義總費(fèi)用
?if(getTaxiPrice(moring,distance) != 0)
?{
??totalPrice = getTaxiPrice(moring,distance);?//調(diào)用計(jì)算費(fèi)用的函數(shù)
?}
?else if(totalPrice != 0)
?{
??totalPrice += getTaxiPrice(afternoon,distance);?//調(diào)用計(jì)算費(fèi)用的函數(shù)
?}
?printf("小明每天打車的總費(fèi)用是:%.2f\n",totalPrice);?//輸出
?return 0;???
}
2016-04-01
float精確度不夠,改成double