唯你人间星火
2022-02-14 16:04
#include <stdio.h>
int getPrice(int distance,int time) {
float cost;
if (distance <= 3) {
cost = 14;
}
else
{
if (time >= 5 && time < 23) {
cost = (distance - 3) * 2.3 + 14;
}else {
cost = (distance - 3) * 2.3 * 1.2 + 14;
}
}
return cost;
}
int main() {
int distance,time;
float cost;
distance = 12;
time = 9;
float cost1=getPrice(distance, time);
time = 18;
float cost2 = getPrice(distance, time);
cost = cost1 + cost2;
printf("小明每天要花%f元坐车", cost);
return 0;
}
还没有人回答问题,可以看看其他问题
C语言入门
926025 学习 · 20793 问题
相似问题