#include <stdio.h>int f(int time,int distance){ double money; if(time>=5&&time <=23) if(distance<=3) money=13; else money=13+2.3*(distance-3); else if(distance<=3) money=14; else money=14+2.3*1.2*(distance-3); return money;}int main(){ int a,distances=12, time1=9,time2=18,b; a=f(time1,distances); printf("上班的车费是:%d\n",&a); b=f(time2,distances); printf("下班的车费是:%d\n",&b); return 0;}
2 回答
已采纳
望远
TA贡献1017条经验 获得超1032个赞
#include <stdio.h> double f(int time,int distance)//注意返回值类型,money是double类型,否则会损失精度 { double money=0; if(time>=5&&time <=23) if(distance<=3) money=13; else money=13+2.3*(distance-3); else if(distance<=3) money=14; else money=14+2.3*1.2*(distance-3); return money; } int main() { int distances=12, time1=9,time2=18; double a,b;//a,b应该定义为double类型 a=f(time1,distances); printf("上班的车费是:%.3lf\n",a);//输出数据,你原来输出的是地址 b=f(time2,distances); printf("下班的车费是:%.3lf\n",b); return 0; }
- 2 回答
- 0 关注
- 1666 浏览
添加回答
举报
0/150
提交
取消