最近中文字幕高清中文字幕无,亚洲欧美高清一区二区三区,一本色道无码道dvd在线观看 ,一个人看的www免费高清中文字幕

為了賬號(hào)安全,請(qǐng)及時(shí)綁定郵箱和手機(jī)立即綁定

請(qǐng)大神幫忙看看還有哪里不對(duì)的嗎?(運(yùn)行結(jié)果已正確)

#include <stdio.h>

?double getTotalCost(float n,float t)

? ? {

? ? ? ? double cost;

? ? ? ? if(n<=3)

? ? ? ? {

? ? ? ? ? ? cost=13+1;

? ? ? ? }

? ? ? ? else

? ? ? ? {

? ? ? ? ? ? if(5<=t&&t<23)

? ? ? ? ? ? {

? ? ? ? ? ? ? ? cost=13+1+2.3*(n-3);

? ? ? ? ? ? }

? ? ? ? ? ? else

? ? ? ? ? ? {

? ? ? ? ? ? ? ? cost=13+1+2.3*(n-3)*1.2;

? ? ? ? ? ? }

? ? ? ? }

? ? ? ? return cost;

? ? }

int main()

{

? ? printf("小明每天打車總費(fèi)用為%f:",getTotalCost(12,9)+getTotalCost(12,18));

? ? return 0;

}


正在回答

5 回答

我是做安卓的,因?yàn)楣ぷ餍枰_始學(xué)習(xí)C語(yǔ)言

貼上我自己的代碼,相互交流哈。

#include <stdio.h>

int getRent(int mile, int time) {

? ? int startRent = 13; //起步價(jià)

? ? int rentPerMile = 2.3; //每公里單價(jià)

? ? int extraRent = 1; //燃油附加稅

? ? int rent = 0; //打車費(fèi)用

? ??

? ? //打車時(shí)間小于0或大于24都是不合法的,輸出提示信息并結(jié)束方法

? ? if(time < 0 || time > 24) {

? ? ? ? printf("您輸入的打車時(shí)間為:%d,這不是一個(gè)合法的時(shí)間,請(qǐng)重新檢查您的輸入??!");

? ? ? ? return 0;

? ? }

? ? //在23點(diǎn)和5點(diǎn)前打車,每公里單價(jià)計(jì)費(fèi)加收20%

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

? ? ? ? rentPerMile *= rentPerMile*1.2;

? ? }

? ??

? ? if(mile <= 3) {

? ? ? ? rent = startRent + extraRent;

? ? } else {

? ? ? ? rent = startRent + rentPerMile*(mile-3) + extraRent;

? ? }

? ? return rent;

}

int main()

{

? ? int onWorkRent = getRent(12, 9);

? ? int offWorkRent = getRent(12, 18);

? ? printf("您的上班打車費(fèi)用為:%d 元\n", onWorkRent);

? ? printf("您的下班打車費(fèi)用為:%d 元\n", offWorkRent);

? ? printf("您一天的打車費(fèi)用為:%d 元", onWorkRent+offWorkRent);

? ? return 0;

}


1 回復(fù) 有任何疑惑可以回復(fù)我~

是呀,用float或者都變了好一些,int不能輸出小數(shù)的

0 回復(fù) 有任何疑惑可以回復(fù)我~

還是該用float類型,全用int類型,因?yàn)樽詣?dòng)轉(zhuǎn)型等原因,最后的值就不對(duì)了~

0 回復(fù) 有任何疑惑可以回復(fù)我~

我覺得把起步價(jià)這些值單獨(dú)定義出來(lái), 這樣以后這些值有變化的話, 便于修改。就不用在代碼里面到處去找需要修改的地方了

目前不知道C語(yǔ)言里面是否可以主動(dòng)拋異常,所以只通過(guò)打印的方式提示函數(shù)的參數(shù)傳入有誤。這里只考慮了打車時(shí)間的參數(shù)非法問(wèn)題,沒考慮公里數(shù)為負(fù)等情況。

打車公里數(shù)和時(shí)間都只考慮了int類型的~~

0 回復(fù) 有任何疑惑可以回復(fù)我~
#1

慕妹1614475 提問(wèn)者

對(duì)對(duì)對(duì)!單獨(dú)定義雖然麻煩但是清晰明了而且出錯(cuò)容易修改,謝謝指教!哈哈哈!
2017-06-29 回復(fù) 有任何疑惑可以回復(fù)我~
#2

奇怪的阿怪

第15行應(yīng)該是rentPerMile=rentPerMile*1.2或者是rentPerMile*=1.2吧
2017-07-31 回復(fù) 有任何疑惑可以回復(fù)我~

沒有問(wèn)題吧

0 回復(fù) 有任何疑惑可以回復(fù)我~

舉報(bào)

0/150
提交
取消

請(qǐng)大神幫忙看看還有哪里不對(duì)的嗎?(運(yùn)行結(jié)果已正確)

我要回答 關(guān)注問(wèn)題
微信客服

購(gòu)課補(bǔ)貼
聯(lián)系客服咨詢優(yōu)惠詳情

幫助反饋 APP下載

慕課網(wǎng)APP
您的移動(dòng)學(xué)習(xí)伙伴

公眾號(hào)

掃描二維碼
關(guān)注慕課網(wǎng)微信公眾號(hào)