ANU_Yang
2017-12-20 17:31
这个结果对吗?
#include <stdio.h>
//start_time 上车时间 ,total_km 里程数
double TotalAmt(double start_time, double total_km)
{
double unit_price=2.3; //每公里单价计费2.3元
double flag_fall_price = 13; //起步价13元(包含3公里)
double begin_time=23;//每公里单价计费加收20%。开始时间
double end_time=5;//每公里单价计费加收20%。结束时间
double additional=1;// 每次乘车加收1元钱的燃油附加税
double start_km = 3; //起步包含3公里
double total_amt;//总费用
if( start_time >= begin_time || start_time < end_time){
unit_price *= 1.2;
}
if( total_km <= start_km)
{
total_amt = flag_fall_price + additional;
}
else
{
total_amt = flag_fall_price + additional + (total_km - start_km) * unit_price;
}
return total_amt;
}
int main()
{
double amt = 0;
amt+=(TotalAmt(9,12)+TotalAmt(18,12));
printf("小明每天打车的总费用为%f元", amt);
return 0;
}
#include <stdio.h> /** * @real_miles double 实际里程数 * @now_time double 上车时间 */ double getTotalMoney(double real_miles, double now_time) { int start, gasPlus, miles, start_miles, begin_time, end_time, now; double per, total; miles = (int)real_miles; //对乘客友好的floor型实际里程数 now = (int)now_time; //上车时间 //定义常量 begin_time = 23; //夜间增收起始时间 end_time = 5; //早间增收截止时间 start = 13; //起步费 gasPlus = 1; //燃油费 per = 2.3; //单价 start_miles = 3; //起步公里3公里 if( now > begin_time || now <= end_time){ per *= 1.2; } if( miles <= start_miles){ total = start + gasPlus; }else { total = start + gasPlus + (miles - start_miles) * per; } return total; } int main() { double totalMoney = 0; totalMoney += getTotalMoney(12, 9); totalMoney += getTotalMoney(12, 18); printf("小明每天打车的总费用为%f元", totalMoney); return 0; }
#include <stdio.h>
double getTotalMoney(double real_miles, double now_time)
{
int start, gasPlus, miles, start_miles, begin_time, end_time, now;
double per, total;
miles = (int)real_miles;
now = (int)now_time;
begin_time = 23;
end_time = 5;
start = 13;
gasPlus = 1;
per = 2.3;
start_miles = 3;
if( now > begin_time || now <= end_time){
per *= 1.2;
}
if( miles <= start_miles){
total = start + gasPlus;
}else {
total = start + gasPlus + (miles - start_miles) * per;
}
return total;
}
int main()
{
double totalMoney = 0;
totalMoney += getTotalMoney(12, 9);
totalMoney += getTotalMoney(12, 18);
printf("小明每天打车的总费用为%f元", totalMoney);
return 0;
}
C语言入门
926210 学习 · 20797 问题
相似问题