为什么这样得到答案那么奇怪,怎么不是57.2
#include <stdio.h>
float rule(int t, float distance);
int main()
{
float distance = 12;
int t01 = 9;
int t02 = 18;
float xiaoming ;
xiaoming = rule(t01, distance) + rule(t02,distance );
printf("小明每天打车花费%f", xiaoming);
return 0;
}
float rule(int t, float distance)
{
float sum = 0;
float price = 0;
if ( (t >= 23 && t <=24) || (t >= 0 && t<5 ) )
{
price = 4.3;
}
if(t >= 5 && t < 23)
{
price = 2.3;
}
sum = price * distance;
if(sum<=13)
{
sum = 13;
}
sum = sum + 1;
return sum;
}