共同探讨最好的代码
#include <stdio.h>
//判断是否需要额外20%费用
float getAddition(int times){
if(times>=23 || times<5){
return 1.2;
}else{
return 1;
}
}
//获取往返路程花费 需要来回的时间 路程distance
float getCost(int goTime,int backTime,int distance)
{
float cost=13;
if(distance<=3){
return cost+1;
}else{
cost=distance*getAddition(goTime)*2.3+1;
cost+=distance*getAddition(backTime)*2.3+1;
return cost<13? 13: cost;
}
}
int main()
{
printf("上班打车总花费是%f",getCost(4,24,12));
return 0;
}