无名氏的朋友
2025-02-05 04:27
#include <stdio.h>
int time_(int t){
if(t>23||t<=5){ //夜间时段的判定
return 1;
}
else{
return 0;
}
}
float price(int x,int t ){ //单次车费的计算
float p;
if(time_(t)==0){ //普通时间段的车费
if(x<=3){
p = 13+ 1;
}
else{
p = 13+ (x-3)*2.3 +1;
}
}
else{
if(x<=3){ //高价时间段的车费
p = 13+ 1;
}
else{
p = 13+ (x-3)*2.3*1.2 +1;
}
}
return p;
}
int main()
{
int h1 =9, h2 =18, L =12;
float sum = price(L,h1)+price(L,h2);
printf("小明打车的总费用为%.1f元。\n",sum);
return 0;
}
还没有人回答问题,可以看看其他问题
C语言入门
926466 学习 · 20800 问题
相似问题