慕余一
2020-11-01 14:11
#include <stdio.h>
int main()
{
double sum;
sum =taxifee(9,12)+taxifee(18,12);
return 0;
}
double taxifee(double clock,double miles)
{
double fee;
if(miles<=3)
{
fee = 14;
}
else
{
if(clock>=23||clock<5)
{
fee = 13+1+2.3*(miles-3)*1.2;
printf("夜间打车的费用是%lf",fee);
}
else
{
fee = 13+1+2.3*(miles-3);
printf("日间打车的费用是%lf",fee);
}
}
return fee;
}
#include <stdio.h> double fare(unsigned hour, double kilo) { double money = 13; if (kilo > 3) if (hour < 5 || hour >= 23) money += ((kilo - 3) * 2.3) * 1.2; else money += (kilo - 3) * 2.3; return money + 1; } int main() { double car_fare; car_fare = fare(9, 12) + fare(18, 12); printf("小明每天的打车总费用%lf\n", car_fare); return 0; }
主函数和自定义函数位置反了,而且你没输出sum
可以这么玩
#include <stdio.h>
double taxifee(double clock, double miles)
{
double fee;
if(miles<=3)
{
fee = 14;
}
else
{
if(clock>=23||clock<5)
{
fee = 13+1+2.3*(miles-3)*1.2;
printf("夜间打车的费用是%lf",fee);
}
else
{
fee = 13+1+2.3*(miles-3);
printf("日间打车的费用是%lf",fee);
}
}
return fee;
}
int main()
{
double sum;
sum =taxifee(9,12)+taxifee(18,12);
printf("小明每天的打车费为%f",sum);
return 0;
}
C语言入门
926020 学习 · 20793 问题
相似问题