#include <stdio.h>
int gongli;
double qian;
int shijian;
if(shijian>23||shijian<5)
{
if(gongli<=3)
{
qian=14;
return qian;
}
else
{
qian == 14+2.76*(gongli-3);
return qian;
}
}
else
{
if(gongli<=3)
return qian;
}
else
{
qian == 14+2.3*(gongli-3);
return qian;
}
}
}
int main()
{int gongli ==12;
int shijian == 9;
printf("每天打车的总费用%lf",qian);
return 0;
}
按照你的思路改了下你的代码 你自己对比看下吧。
#include <stdio.h> int gongli = 12;int shijian = 9;float qian(){ if(shijian > 23 || shijian < 5) { if(gongli <= 3) { return 13; } else { return 13 + 2.3 * ( gongli - 3 ) * 1.2; } } else { if(gongli <= 3){ return 13; } else { return 13 + 2.3 * (gongli-3); } }} int main(){ printf("每天打车的总费用%lf",qian()); return 0;}