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

哪儿错了?

#include <stdio.h>
double getPrice (int hours,double distances)
{
    double getPrice=0;
    double distances=0;
    int startPrice=13;
    double perPrice=2.3;
    if(hours<0 || hours>24)
    {
        printf("请输入正确时间\n");
    }
    if(hours<5 && hours>=23)
    {
        perPrice*=1.2;
    }
    if(distances>3)
    {
        getPrice=startPrice+perPrice*(distances-3);
    }
    else if
    {
        getPrice=startPrice;
    }
    getPrice+=1;
    return totalPrice;
}
int main()
{
    int totalPrice;
    double getPriceMoring=getPrice(9,12);
    double getPriceEvening=getPrice(18,12);
    double totalPrice=getPriceMoring+getPriceEvening;
    printf("小明每天打车的总费用为%f\n",totalPrice);
   return 0;
}

正在回答

2 回答

#include <stdio.h>

double getPrice (int hours,double distances)

{

    double getPrice=0;

    double distancess=0;

    int startPrice=13;

    double perPrice=2.3;

    if(hours<0 || hours>24)

    {

        printf("请输入正确时间\n");

        return 0;

    }

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

    {

        perPrice*=1.2;

    }

    if(distances>3)

    {

        getPrice=startPrice+perPrice*(distances-3);

    }

    else 

    {

        getPrice=startPrice;

    }

    getPrice+=1;

    return getPrice;

}

int main()https://www.imooc.com/code/5642#editor-tabs-c

{

    //int totalPrice;

    double getPriceMoring=getPrice(9,12);

    double getPriceEvening=getPrice(18,12);

    double totalPrice=getPriceMoring+getPriceEvening;

    printf("小明每天打车的总费用为%g\n",totalPrice);

   return 0;

}


0 回复 有任何疑惑可以回复我~
hello.c: In function 'getPrice':
hello.c:5:12: error: 'distances' redeclared as different kind of symbol
     double distances=0;
            ^~~~~~~~~
hello.c:2:35: note: previous definition of 'distances' was here
 double getPrice (int hours,double distances)
                                   ^~~~~~~~~
hello.c:21:5: error: expected '(' before '{' token
     {
     ^
hello.c:25:12: error: 'totalPrice' undeclared (first use in this function)
     return totalPrice;
            ^~~~~~~~~~
hello.c:25:12: note: each undeclared identifier is reported only once for each function it appears in
hello.c: In function 'main':
hello.c:32:12: error: conflicting types for 'totalPrice'
     double totalPrice=getPriceMoring+getPriceEvening;
            ^~~~~~~~~~
hello.c:29:9: note: previous declaration of 'totalPrice' was here
     int totalPrice;
         ^~~~~~~~~~


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

举报

0/150
提交
取消
C语言入门
  • 参与学习       924400    人
  • 解答问题       20753    个

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

进入课程

哪儿错了?

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