大佬们 我这输出的数字为什么这么大,,

来源:5-9 递归函数练习

About_Mr

2018-10-14 14:12


C  递归函数

写回答 关注

1回答

  • qq_天下第一卦_dfgkpZ
    2018-12-01 12:24:45
    已采纳

    #include <stdio.h>

    double TaxiPrice(int hours,int distance)

    {

    double totalPrice = 0.0; //定义打车费用 

    double perPrice = 2.3; //定义每公里单价计费 

    int startPrice = 13; //定义起步价 

    int tax=1;    //定义燃油附加税


    if(hours<0 || hours>24){

    printf("请填写正确的时间\n");

    return 0;

    }

    else if(!(hours>=5 && hours<23)) //判断打车时间是否要增加费用

    perPrice *= 1.2; //费用增加20%                         


    if(distance >3) //判断公里数

    totalPrice = startPrice +(distance - 3)*perPrice + tax; //计算价钱

    else

    totalPrice = startPrice + tax;    

    return totalPrice;

    }

    int main()

    {

    int moring = 9; //定义上午打车时间

    int afternoon = 18; //定义下午打车时间

    int distance = 12; //定义打车公里数

    double allPrice = 0; //定义总费用

    allPrice = TaxiPrice(moring,distance) + TaxiPrice(afternoon,distance); //调用计算费用的函数

    printf("小明每天打车的总费用是:%.2f\n",allPrice); //输出

    return 0;    

    }


C语言入门

C语言入门视频教程,带你进入编程世界的必修课-C语言

924594 学习 · 20763 问题

查看课程

相似问题