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

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

同學們幫忙看一下,哪錯了啊

#include <stdio.h>

int cost(int distance,int time)

{

? ? double price = 2.3;

? ? double cost;

? ? if(distance<=3){

? ? ? ? cost = 13+1;

? ? }else if(time<=23 && time>5){

? ? ? ? cost = (distance-3)*price+1+13;

? ? }else{

? ? ? ? cost = (distance-3)*(price*1.2)+1+13;

? ? }

}


int main()

{?

? ? double allcost = cost(12,9)+cost(12,18);

? ? printf("小明每天打車是%f塊錢",allcost);

? ??

? ??

? ??

? ? return 0;

}


正在回答

2 回答

#include?<stdio.h>
float?cost(int?distance,int?time)
{
????double?price?=?2.3;????
????double?cost;????
????if(distance?<=?3)
????{????????
????????cost?=?13?+?1;????
????}
????else?if(time?<?23?&&?time>=5)
????{????????
????????cost?=?(distance?-?3)?*?price?+?1?+?13;????
????}
????else
????{????
????????cost?=?(distance?-?3)?*?(price?*?1.2)?+?1?+?13;
????}????
????return?cost;
}
int?main()
{
?????double?allcost?=?cost(12,9)+cost(12,18);
?????printf("小明每天打車是%0.1f塊錢",allcost);????
?????return?0;
}
1、定義cost函數為int型卻沒有返回值,即沒有return?cost。


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

#include <stdio.h>


int cost(int distance,int time)


{


? ? double price = 2.3;


? ? double costs;


? ? if(distance<=3){


? ? ? ? costs = 14;


? ? }else if(time<=23 || time>=5){


? ? ? ? costs = (distance-3)*price+1+13;

? ? ? ? printf("白天車費為:%f\n",costs);


? ? }else{


? ? ? ? costs = (distance-3)*(price*1.2)+1+13;

? ? ? ? printf("夜間車費為:%f\n",costs);

? ? }


}


int main()


{?


? ? double allcost = cost(12,9)+cost(12,18);


? ? printf("小明每天打車是%f塊錢",allcost);

? ??

? ? return 0;


}


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

qq_慕慕9429610 提問者

兄弟運行一下,還是錯的
2019-05-17 回復 有任何疑惑可以回復我~

舉報

0/150
提交
取消
C語言入門
  • 參與學習       926905    人
  • 解答問題       21533    個

C語言入門視頻教程,帶你進入編程世界的必修課-C語言

進入課程

同學們幫忙看一下,哪錯了啊

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

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

幫助反饋 APP下載

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

公眾號

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