大神速来!5-14的综合练习,跑不出来,错在哪?

来源:5-14 综合练习

NodeOS

2016-02-20 12:00

#include <stdio.h>
float price(int dictance,int useTime)
{
   int startPrice = 13;
   float fuel = 1;
   float milePrice = 2.3;
   float totalPrice;
   while(useTime<5||useTime>=23)
   {
       if(useTime<0||useTime>24)
       {
           printf("%s\n","时间输入有误。");
           return 0;
           break;
       }
       else
       {
           milePrice*=1.2;
           break;
       }
   }
   if(distance<=3)
   {
       totalprice = startPrice+fuel;
   }
   else
   {
       totalPrice = startPrice+milePrice*(dictance-3)+fuel;
   }
   return totalPrice;
}

int main()
{
   int amTime = 9;
   int pmTime = 18;
   int distance = 12;
   printf("小明上午打车的费用是%f\n",price(distance,amTime));
   printf("小明下午打车的费用是%f\n",price(distance,pmTime));
   printf("小明打车的总费用是%f\n",price(distance,amTime)+price(distance,pmTime));
   return 0;
}

运行结果如下:

/249/5642/CD9l/hello.c: In function 'price':
/249/5642/CD9l/hello.c:22:8: error: 'distance' undeclared (first use in this function)
    if(distance<=3)
       ^
/249/5642/CD9l/hello.c:22:8: note: each undeclared identifier is reported only once for each function it appears in
/249/5642/CD9l/hello.c:24:9: error: 'totalprice' undeclared (first use in this function)
        totalprice = startPrice+fuel;

写回答 关注

2回答

  • 侠客岛的含笑
    2016-02-21 16:02:45
    已采纳

    小心使得万年船

  • NodeOS
    2016-02-20 12:17:25

    原来是distance误写成dictance,同时totalPrice的P小写成p了,太粗心!

C语言入门

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

926027 学习 · 20793 问题

查看课程

相似问题