出租车收费。某城市普通出租车收费标准如下:起步里程3公里起步费用10元;超起步里程后10公里内每公里租费2元;超过10公里以上的部分加50的回空补贴费即每公里租费3元。营运过程中因路阻及乘客要求临时停车的每5分钟按1公里租费计收。运价计费尾数四舍五入保留到元。编写程序输入行驶里程公里与等待时间分钟计算并输出乘客应支付的车费元。编写c语言程序
#include <stdio.h>
#include <math.h>
int main() {
const int START_DISTANCE = 3; // 起步里程
const int START_FEE = 10; // 起步费用
const int FIRST_TEN_KM = 10; // 超起步里程后10公里内
const float FIRST_TEN_KM_FEE = 2.0; // 每公里租费
const float OVER_TEN_KM_FEE = 3.0; // 超过10公里以上的部分每公里租费
const float WAITING_FEE = 1.0 / 12; // 每5分钟按1公里租费计收
const int WAITING_TIME_UNIT = 5; // 等待时间单位为5分钟
float distance, waitingTime, fee; // 行驶里程、等待时间、车费
int totalFee; // 车费取整后的整数部分
printf("请输入行驶里程(公里):");
scanf("%f", &distance);
printf("请输入等待时间(分钟):");
scanf("%f", &waitingTime);
// 计算车费
if (distance <= START_DISTANCE) {
fee = START_FEE;
} else if (distance <= START_DISTANCE + FIRST_TEN_KM) {
fee = START_FEE + (distance - START_DISTANCE) * FIRST_TEN_KM_FEE;
} else {
fee = START_FEE + FIRST_TEN_KM * FIRST_TEN_KM_FEE + (distance - START_DISTANCE - FIRST_TEN_KM) * OVER_TEN_KM_FEE;
}
fee += ceil(waitingTime / WAITING_TIME_UNIT) * WAITING_FEE;
// 取整
totalFee = (int) round(fee);
printf("乘客应支付车费:%d元\n", totalFee);
return 0;
}
原文地址: https://www.cveoy.top/t/topic/NfW 著作权归作者所有。请勿转载和采集!