为什么输入任何数算出来都是1..

来源:5-14 综合练习

NCCTG

2017-11-13 23:26

#include<stdio.h>

double taxifee(double hours,double distance);

int main()

{

printf("enter hours and distance\n");

int  hours,distance;

double totalprice;

scanf("%lf %lf",&hours,&distance);

taxifee(hours,distance);

printf("the fee is %lf",totalprice);

return 0;

}

double taxifee(double hours,double distance)

{

double totalprice=0.0;

double perprice=2.3;

double startprice=13.0;

if(hours<0||hours>24)

{

printf("enter a correct number~~");

return 0;

}

else if (hours<5&&hours>=23)

{

perprice*=1.2;


}

if(distance<=3)

{

totalprice=startprice;

}

else 

{

totalprice=startprice+(distance-3)*perprice;

}

totalprice++;

return totalprice;

}


写回答 关注

2回答

  • 哦多克3118188
    2017-11-27 16:17:02

    #include<stdio.h>

    double taxifee(double hours,double distance);


    int main()

    {

    printf("enter hours and distance\n");

    int  hours,distance;

    double totalprice;

    scanf("%lf %lf",&hours,&distance);

    taxifee(hours,distance);

    printf("the fee is %lf",totalprice);

    return 0;

    }


    double taxifee(double hours,double distance)

    {

    double totalprice=0.0;

    double perprice=2.3;

    double startprice=13.0;

    if(hours<0||hours>24)

    {

    printf("enter a correct number~~\n");

    return 0;

    }

    else if (hours>=5 && hours<23)

    {

    perprice = perprice;

    }else

    {

        perprice *= 1.2;

    }


    if(distance<=3)

    {

    totalprice=startprice;

    }

    else 

    {

    totalprice=startprice+(distance-3)*perprice;

    }

    totalprice++;

    return totalprice;

    }


  • qq_林木_03826380
    2017-11-14 21:19:01

    else if (hours<5&&hours>=23)这句中的&&应该改为||

C语言入门

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

926025 学习 · 20793 问题

查看课程

相似问题