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

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

求問這個代碼哪里不對?

#include <stdio.h>


int main()

{

? ? float morningPay,eveningPay,totalPay;

? ? morningPay=sum(9,12);

? ? eveningPay=sum(18,12);

? ? totalPay=morningPay+eveningPay;

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

? ? return 0;

}


float sum(int t,int d)

{

? ? int pay;

? ? if(t>5||t<=23)

? ? {

? ? ? ? if(d<=3)

? ? ? ? {

? ? ? ? ? ? pay=13+1;

? ? ? ? }

? ? ? ? else

? ? ? ? {

? ? ? ? ? ? pay=13+(d-3)*2.3+1;

? ? ? ? }

? ? }

? ? else if(t<=5||t>23)

? ? {

? ? ? ? if(d<=3)

? ? ? ? {

? ? ? ? ? ? pay=13+1;

? ? ? ? }

? ? ? ? else

? ? ? ? {

? ? ? ? ? ? pay=13+(d-3)*2.3*1.2+1;

? ? ? ? }

? ? }

? ? return pay;

}


正在回答

4 回答

就語法錯誤來講, 你定義的sum函數是float類型的, 返回值pay也應該是float類型, 然而你定義pay的時候卻定義成了int類型

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

我只知道int pay應該改為double? pay

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

提示是什么意思呢

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

運行失敗

hello.c:?In?function?'main':
hello.c:6:16:?warning:?implicit?declaration?of?function?'sum'?[-Wimplicit-function-declaration]
?????morningPay=sum(9,12);
????????????????^~~
hello.c:?At?top?level:
hello.c:13:7:?error:?conflicting?types?for?'sum'
?float?sum(int?t,int?d)
???????^~~
hello.c:6:16:?note:?previous?implicit?declaration?of?'sum'?was?here
?????morningPay=sum(9,12);
????????????????^~~


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

舉報

0/150
提交
取消

求問這個代碼哪里不對?

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

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

幫助反饋 APP下載

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

公眾號

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