应该是输出69.4元,为什么多了那么多九。求大神指点
因为你打印出来的车费的数据类型是float,还有你写的这个代码的功能对不上题目意思
#include<stdio.h>
float xiaokai(int w,int r,float t,int y,int u)//定义费用函数
{
float jg;
if(w-y>0)
{
jg=(w-y)*t+u+r;
}
else
{
jg=u+r;
}
return jg;
}
float sj(n)//定义时间函数
{
float i;
switch(n)
{
case 1:
i=1.2;
break;
case 2:
i=1.2;
break;
case 3:
i=1.2;
break;
case 4:
i=1;
break;
case 5:
i=1.2;
break;
case 6:
i=1;
break;
case 7:
i=1;
break;
case 8:
i=1;
break;
case 9:
i=1;
break;
case 10:
i=1;
break;
case 11:
i=1;
break;
case 12:
i=1;
break;
case 13:
i=1;
break;
case 14:
i=1;
break;
case 15:
i=1;
break;
case 16:
i=1;
break;
case 17:
i=1;
break;
case 18:
i=1;
break;
case 19:
i=1;
break;
case 20:
i=1;
break;
case 21:
i=1;
break;
case 22:
i=1;
break;
case 23:
i=1.2;
break;
case 24:
i=1.2;
break;
}
return i;
}
int main()
{
printf("%f",xiaokai(12,1,2.3,3,13)*sj(9)/*←括号类填写上班时间*/+xiaokai(12,1,2.3,3,13)*sj(18)/*←括号内填写下班时间*/);
return 0;
}
//输出结果为 69.40002