为了账号安全,请及时绑定邮箱和手机立即绑定

为什么输入任何数算出来都是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;

}


正在回答

2 回答

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

}


0 回复 有任何疑惑可以回复我~

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

0 回复 有任何疑惑可以回复我~

举报

0/150
提交
取消

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

我要回答 关注问题
意见反馈 帮助中心 APP下载
官方微信