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

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

#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 回答


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

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

Wangyj1108 提问者

非常感谢!
2016-04-02 回复 有任何疑惑可以回复我~
#2

瓢_

大神。6666
2016-04-12 回复 有任何疑惑可以回复我~
#3

慕粉17826806337

虽然很华丽,然而他要求算全天的,你 的运行出来的却只有早上,最后应该不需要用if....else if ...了吧
2016-05-26 回复 有任何疑惑可以回复我~

float精确度不够,改成double

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

举报

0/150
提交
取消

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

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

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

帮助反馈 APP下载

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

公众号

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