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

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

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

}


提问者:NCCTG 2017-11-13 23:26

个回答

  • 哦多克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)这句中的&&应该改为||