这是不设置输出小数点的
#include <stdio.h>
float CountCost(int distance,int time)
{
float Cost=0;
if(distance<=3)
{
Cost=13.0;
}
else
Cost=13.0+(distance-3)*2.3;
switch(time)
{
case 23:
case 0:
case 1:
case 2:
case 3:
case 4:
Cost*=1.2;
break;
default:
break;
}
Cost=Cost+1;
return Cost;
}
int main()
{
float TotalCost=0;
float Cost1=CountCost(12,9);
float Cost2=CountCost(12,18);
TotalCost=Cost1+Cost2;
printf("%f",TotalCost);
return 0;
}
这是设置输出一位小数,即%.1f
把所有的float改成doube就没有2了