#include <stdio.h>
float money;
int time1(int t,int f);
if(f<=3)
{
money=13+1;
else
if(t < 23 && t >= 5)
money=13+1+(f-3)*2.3;
else
money=14+(f-3)*2.3*1.2;
return money;
}
int main()
{
printf("小明每天打车的总费用是%d元",time1(9,12)+time1(18,12));
return 0;
}
#include <stdio.h>
double taxCost(int kilometer)
{
extern int when;
double dollar;
if(kilometer<=3)
{
dollar = 14.0;
}
else if (kilometer>3 && when>=23 || when<5)
{
dollar=taxCost(kilometer-1)+2.76;
}
else
{
dollar=taxCost(kilometer-1)+2.3;
}
return dollar;
}
int main()
{
static double cost;
cost=taxCost(12)*2;
printf("xiaoming has cost %.1f dollar for taxi everyday",cost);
return 0;
}
int when=9;
感兴趣也可以看看我写的方法
#include <stdio.h>
double money;
double time1(int t,int f)
{
if(f<=3)
{
money=14;
}
else if(5<=t<23)
{
money=(f-3)*2.3+14;
}
else
{
money=(f-3)*(2.3*1.2)+14;
}
return money;
}
int main()
{
double cost ;
cost= time1(9,12)+time1(18,12);
printf("小明每天打车的总费用是%.1f元",cost);
return 0;
}
给你改了改 你先和自己的对照一下,主要错误是自建函数你用的int,如果想要算出准确数需要用double。第二点错误就是有些粗心,好多地方格式问题。
int time1(int t,int f)后面是花括号{}