问答详情
源自:5-14 综合练习

代码仅供参考

#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;

}


提问者:是百百吖 2024-11-25 18:41

个回答

  • 是百百吖
    2024-11-25 18:41:57

    #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;

    }