是百百吖
2024-11-25 18:41
#include <stdio.h>
double getFree(int time, double distance)
{
double starting_price = 13;//起步价
double starting_distance = 3;//起步里程
double unit_price = 2.3;//单价
double actual_price = (time > 23 || time < 5) ? unit_price * 1.2 : unit_price;//夜间单价
double extra_price = 1;//燃油费
if (distance <= starting_distance)
{
return starting_price + extra_price;
}
else
{
return starting_price + extra_price + actual_price * (distance - starting_distance);
}
}
int main()
{
double resFree = getFree(9, 12) + getFree(18, 12);
printf("%f",resFree);
return 0;
}
#include <stdio.h>
double getFree(int time, double distance)
{
double starting_price = 13;//起步价
double starting_distance = 3;//起步里程
double unit_price = 2.3;//单价
double actual_price = (time > 23 || time < 5) ? unit_price * 1.2 : unit_price;//夜间单价
double extra_price = 1;//燃油费
if (distance <= starting_distance)
{
return starting_price + extra_price;
}
else
{
return starting_price + extra_price + actual_price * (distance - starting_distance);
}
}
int main()
{
double resFree = getFree(9, 12) + getFree(18, 12);
printf("%f",resFree);
return 0;
}
C语言入门
926206 学习 · 20797 问题
相似问题