5-13综合练习 帮我看看有什么地方需要更正的 。thanks
代码可以看到显示了三次小明打车金额为xxx,这里怎么回事?
2015-02-24
你的所提的问题的原因是在double money()这个函数里,当天每进一次double money()函数就会printf();输出一遍,加上你在主函数里的一次输出,正好是三次;我把你程序改了一下,你可以看看
#include <stdio.h>
double money( int hours, double distance)
{
double kilePrice = 2.3;//每公里单价计费2.3元
int beginkm = 3;//包含3公里
int beginPrice = 13;//起步价13元
double endPrice = 0;//总价
if(distance <= 0)
{
printf("请重新输入");
return 0;
}
else if(distance >0 && distance <= 3)
{
//printf("小明打车的金额为14");
return 14;
}
else
{
if(hours < 5 && hours > 23){
endPrice = 1+beginPrice + (distance - beginkm)*2.3*1.2;
//printf("小明打车的金额为%f",endPrice);
return endPrice;
}
else
{
endPrice = 1+beginPrice + (distance - beginkm)*2.3;
//printf("小明打车的金额为%f",endPrice);
return endPrice;
}
}
}
int main()
{
printf("小明打车的金额为%.1f",money(9,12)+money(18,12));
return 0;
}
举报