荒村小枝
2020-12-13 12:33
#include <stdio.h>
int Pay(int dis,char time) {
if(dis <= 3)
return 13;
else if(time == 'A')
return 13+(dis-3)*2.3+1;
else
return 13+(dis-3)*2.3*1.2+1;
}
int main()
{
printf("%d",Pay(12,'A'));
return 0;
}
#include <stdio.h>
float carFee(int length, int hour)
{
int start = 13; //起步价
int start_length = 3; //起步距离
int oil = 1; //燃油附加税
float per_length = 2.3; //单价
if (hour >= 23 || hour < 5){
per_length = per_length * 1.2; //夜间加价20%
}
float total = 0; //总费用
int extend_length = length > start_length ? (length - start_length) : 0;
total = start + oil + extend_length * per_length;
return total;
}
int main()
{
float fee = carFee(12,9) + carFee(12,6);
printf("小明打车总费用:%.2lf",fee);
return 0;
}
我算的往返车费 69.40元
#include <stdio.h>float carFee(int length, int hour){ int start = 13; //起步价 int start_length = 3; //起步距离 int oil = 1; //燃油附加税 float per_length = 2.3; //单价 if (hour >= 23 || hour < 5){ per_length = per_length * 1.2; //夜间加价20% } float total = 0; //总费用 int extend_length = length > start_length ? (length - start_length) : 0; total = start + oil + extend_length * per_length; return total;}int main(){ float fee = carFee(12,9) + carFee(12,6); printf("小明打车总费用:%.2lf",fee); return 0;}
#include <stdio.h>
float taxifee(int clock,int miles)
{
float money;
if(miles<=3)
{
money=14;
printf("费用为14\n");
}
else
{
if(clock>=23 || clock<5)
{
money=13+1+2.3*(miles-3)*1.2;
printf("夜间车费为:%f\n",money);
}
else
{
money=13+1+2.3*(miles-3);
printf("日间车费为:%f\n",money);
}
}
return money;
}
int main()
{
printf("打的总费用:%.1f\n",taxifee(9,12)+taxifee(18,12));
return 0;
}
C语言入门
926207 学习 · 20797 问题
相似问题