#include <stdio.h>
float putmoney(int li,int time)
{
float money;
if(23<=time<=24||0<=time<=5)
{
if(li<=3)
money=14*1.2;
else
money=14*1.2+(li-3)*2.3*1.2;
}
else
{
if(li<=3)
money=14;
else
money=14+(li-3)*2.3;
}
return money;
}
int main()
{
printf("小明上午打车的总费用%f\n",putmoney(12,9)+putmoney(12,6));
return 0;
}
if(23<=time<=24||0<=time<=5) 像0<=time<=5这样是不行的,
改为if(23<=time&&time<=24||0<=time&&time<=5) 参考章节3-7 逻辑运算符
输出的值为全天的打车费用69.4元
#include <stdio.h>
float allmoney(int dis,int time)
{
float money;
if((time<=24&&time>=23)||(time<=5&&time>=0))
{
if(dis<=3)
money=13+1;
else
money=13+(dis-3)*2.3*1.2+1;
}
else
{
if(dis<=3)
money=13+1;
else
money=13+1+(dis-3)*2.3;
}
return money;
}
int main()
{
printf("小明打车的总费用%f\n",allmoney(12,9)+allmoney(12,6));
return 0;
}
这是我修改过的