第七色在线视频,2021少妇久久久久久久久久,亚洲欧洲精品成人久久av18,亚洲国产精品特色大片观看完整版,孙宇晨将参加特朗普的晚宴

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

請大神幫忙看看還有哪里不對的嗎?(運行結(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:",getTotalCost(12,9)+getTotalCost(12,18));

? ? return 0;

}


正在回答

5 回答

我是做安卓的,因為工作需要開始學(xué)習(xí)C語言

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

#include <stdio.h>

int getRent(int mile, int time) {

? ? int startRent = 13; //起步價

? ? int rentPerMile = 2.3; //每公里單價

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

? ? int rent = 0; //打車費用

? ??

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

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

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

? ? ? ? return 0;

? ? }

? ? //在23點和5點前打車,每公里單價計費加收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("您的上班打車費用為:%d 元\n", onWorkRent);

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

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

? ? return 0;

}


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

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

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

還是該用float類型,全用int類型,因為自動轉(zhuǎn)型等原因,最后的值就不對了~

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

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

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

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

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

慕妹1614475 提問者

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

奇怪的阿怪

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

沒有問題吧

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

舉報

0/150
提交
取消

請大神幫忙看看還有哪里不對的嗎?(運行結(jié)果已正確)

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

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

幫助反饋 APP下載

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

公眾號

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