我的答案是69.400002,求大神忙我看看

来源:5-14 综合练习

Wangyj1108

2016-04-01 14:30

#include <stdio.h>

float str(i,j)
{
    float n;
    if(i<=3)
    n=14;
    else if(j>=23||j<=5)
    n=14+(i-3)*2.3*1.2;
    else
    n=14+(i-3)*2.3;
    return n;
    }
int main()
{
    printf("小明每天打车费用为%f",str(12,9)+str(12,18));
    return 0;
}


写回答 关注

2回答

  • 屎大彪
    2016-04-01 19:49:48
    已采纳

    #include <stdio.h>
    double getTaxiPrice(int hours,int distance)
    {
     double totalPrice = 0.0; //定义打车费用
     double perPrice = 2.3; //定义每公里单价计费
     int startPrice = 13; //定义起步价

     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; //计算价钱
     }
     else
     {
      totalPrice = startPrice;   
     }
     totalPrice++; //加一块钱的燃油费
     return totalPrice;
    }
    int main()
    {
     int moring = 9; //定义上午打车时间
     int afternoon = 18; //定义下午打车时间
     int distance = 12; //定义打车公里数
     double totalPrice = 0; //定义总费用
     if(getTaxiPrice(moring,distance) != 0)
     {
      totalPrice = getTaxiPrice(moring,distance); //调用计算费用的函数
     }
     else if(totalPrice != 0)
     {
      totalPrice += getTaxiPrice(afternoon,distance); //调用计算费用的函数
     }
     printf("小明每天打车的总费用是:%.2f\n",totalPrice); //输出
     return 0;   
    }

    慕粉1782...

    虽然很华丽,然而他要求算全天的,你 的运行出来的却只有早上,最后应该不需要用if....else if ...了吧

    2016-05-26 16:44:31

    共 3 条回复 >

  • dyr
    2016-04-01 19:55:52

    float精确度不够,改成double

C语言入门

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

926894 学习 · 21464 问题

查看课程

相似问题