#include <stdio.h>
int main()
{ int moning=9,after=18,leave=12;
float getmoney;
printf("上班时间=%d点\n",moning);
printf("下班时间=%d点\n",after);
printf("公司离家距离=%d公里\n",leave);
man(moning,leave); /*调用函数求上班打车花费的费用*/
man(after,leave); /*调用函数求下班打车花费的费用*/
getmoney=man(moning,leave)+man(after,leave); /*求小明总共打车花费的费用*/
printf("小明打车总费用%0.2f元\n",getmoney);
return 0;
}
man(int time,int leave)
{
float monovalent=2.3,sum;
if(time>24||time<0) //判断输入时间是否符合实际
{
printf("输入的时间无效");
}
else
{
if(time>=23&&time<5) //判断是否需要加收费用
{
monovalent*=1.2;
}
}
if(leave<=3) //判断里程是否在起步价之内
{
sum=13+1;
}
else
{
sum=(leave-3)*monovalent+14;
}
return sum;
}#include <stdio.h>
double man(int, int);
int main()
{ int moning=9,after=18,leave=12;
double getmoney;
printf("上班时间=%d点\n",moning);
printf("下班时间=%d点\n",after);
printf("公司离家距离=%d公里\n",leave);
man(moning,leave); /*调用函数求上班打车花费的费用*/
man(after,leave); /*调用函数求下班打车花费的费用*/
getmoney=man(moning,leave)+man(after,leave); /*求小明总共打车花费的费用*/
printf("小明打车总费用%0.2f元\n",getmoney);
return 0;
}
double man(int time,int leave)
{
double monovalent=2.3,sum;
if(time>24||time<0) //判断输入时间是否符合实际
{
printf("输入的时间无效");
}
else
{
if(time>=23&&time<5) //判断是否需要加收费用
{
monovalent*=1.2;
}
}
if(leave<=3) //判断里程是否在起步价之内
{
sum=13+1;
}
else
{
sum=(leave-3)*monovalent+14;
}
return sum;
}
第二行添加了函数声明和返回值,float都改为了double,感觉double会好点。
我试过,加了float, 系统报错
man函数在定义是没有写上返回类型,在前面加上 float 吧