亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定

學霸看看有什么問題?

#include <stdio.h>

double price(int hours,int distance)

{

? ?double taxiprice=0.0;

? ?double start=13;

? ?double everydistance=2.3;

? ?if(hours<0||hours>24)

? ?{

? ? ? ?printf("請輸入正確時間\n");

? ? ? ?return 0;

? ?}

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

? ?{

? ? ? ?if(distance>3)

? ? ? ?{

? ? ? ? ? ?taxiprice=start+(distance-3)*everydistance;

? ? ? ?}

? ? ? ?else

? ? ? ?{

? ? ? ? ? ?taxiprice=start;

? ? ? ?}

? ?}

? ?else

? ?{

? ? ? ?if(distance>3)

? ? ? ?{

? ? ? ? ? ?taxiprice=start+(distance-3)*everydistance*1.2;

? ? ? ?}

? ? ? ?else

? ? ? ?{

? ? ? ? ? ?taxiprice=start;

? ? ? ?}

? ? taxiprice++;

? ? return taxiprice; ??

? ?}

? ?int main()

? ?{

? ? ? ?int moring=9;

? ? ? ?int afternoon=18;

? ? ? ?int distance=12;

? ? ? ?double taxiprice=0.0;

? ? ? ?taxiprice=price(moring,distance)+price(afternoon,distance);

? ? ? ?printf("小明每天打車總費用:%f\n",taxiprice);

? ? ? ?return 0;

? ?}

}


正在回答

1 回答

1. main函數結尾多了一個括號,price函數結尾少了一個括號,這導致這段代碼編譯時就出錯。2. 應該在else if結束前加一個return taxiprice,或者在函數price結尾加return,源代碼輸出價格為0就是因為函數沒有正確返回值。

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

奮球 提問者

非常感謝!
2017-08-06 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消

學霸看看有什么問題?

我要回答 關注問題
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號