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

为什么sum加不起来,请教大神!

#include <stdio.h>

int calc_price(float mile, int time)

{

    float sum_price;

    float per_price = 2.3;

    int primary_price = 13;

    if(time >= 5 && time < 23)

    {

        if(mile < 3)

            sum_price = primary_price + mile * per_price + 1;

        else

            sum_price = primary_price + (mile - 3) * per_price + 1;

        printf("您在%d点打车,打车费用为%.2f\n", time, sum_price);

    }

    else

    {

        if(mile < 3)

            sum_price = primary_price + mile * (per_price * 0.2) + 1;

        else

            sum_price = primary_price + (mile - 3) * (per_price * 0.2) + 1;

        printf("您在%d点打车,打车费用为%.2f\n", time, sum_price);

    }

    return sum_price;

}

int main()

{

    printf("打的总费用:%.2f\n",calc_price(12, 9) + calc_price(12, 18));

    return 0;

}


正在回答

1 回答

你定义了是个整数 int calc_price(float mile, int time),打印printf却是%f;int换成 float试试

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

举报

0/150
提交
取消

为什么sum加不起来,请教大神!

我要回答 关注问题
微信客服

购课补贴
联系客服咨询优惠详情

帮助反馈 APP下载

慕课网APP
您的移动学习伙伴

公众号

扫描二维码
关注慕课网微信公众号