課程
/后端開發(fā)
/C
/C語言入門
C? 遞歸函數(shù)
2018-10-14
源自:C語言入門 5-9
正在回答
#include <stdio.h>
double TaxiPrice(int hours,int distance)
{
double totalPrice = 0.0; //定義打車費(fèi)用?
double perPrice = 2.3; //定義每公里單價(jià)計(jì)費(fèi)?
int startPrice = 13; //定義起步價(jià)?
int tax=1;? ? //定義燃油附加稅
if(hours<0 || hours>24){
printf("請(qǐng)?zhí)顚懻_的時(shí)間\n");
return 0;
}
else if(!(hours>=5 && hours<23)) //判斷打車時(shí)間是否要增加費(fèi)用
perPrice *= 1.2; //費(fèi)用增加20%? ? ? ? ? ? ? ? ? ? ? ? ?
if(distance >3) //判斷公里數(shù)
totalPrice = startPrice +(distance - 3)*perPrice + tax; //計(jì)算價(jià)錢
else
totalPrice = startPrice + tax;? ??
return totalPrice;
int main()
int moring = 9; //定義上午打車時(shí)間
int afternoon = 18; //定義下午打車時(shí)間
int distance = 12; //定義打車公里數(shù)
double allPrice = 0; //定義總費(fèi)用
allPrice = TaxiPrice(moring,distance) + TaxiPrice(afternoon,distance); //調(diào)用計(jì)算費(fèi)用的函數(shù)
printf("小明每天打車的總費(fèi)用是:%.2f\n",allPrice); //輸出
return 0;? ??
舉報(bào)
C語言入門視頻教程,帶你進(jìn)入編程世界的必修課-C語言
2 回答大佬們,為什么我輸出的數(shù)字超級(jí)大啊
2 回答大佬們?yōu)槭裁次疫@個(gè)不行
1 回答大佬們,為什么這個(gè)不行
2 回答大佬們幫我看看為什么輸出會(huì)有0.000002
3 回答為什么輸出錯(cuò)誤,大佬們幫幫忙
Copyright ? 2025 imooc.com All Rights Reserved | 京ICP備12003892號(hào)-11 京公網(wǎng)安備11010802030151號(hào)
購課補(bǔ)貼聯(lián)系客服咨詢優(yōu)惠詳情
慕課網(wǎng)APP您的移動(dòng)學(xué)習(xí)伙伴
掃描二維碼關(guān)注慕課網(wǎng)微信公眾號(hào)
2018-12-01
#include <stdio.h>
double TaxiPrice(int hours,int distance)
{
double totalPrice = 0.0; //定義打車費(fèi)用?
double perPrice = 2.3; //定義每公里單價(jià)計(jì)費(fèi)?
int startPrice = 13; //定義起步價(jià)?
int tax=1;? ? //定義燃油附加稅
if(hours<0 || hours>24){
printf("請(qǐng)?zhí)顚懻_的時(shí)間\n");
return 0;
}
else if(!(hours>=5 && hours<23)) //判斷打車時(shí)間是否要增加費(fèi)用
perPrice *= 1.2; //費(fèi)用增加20%? ? ? ? ? ? ? ? ? ? ? ? ?
if(distance >3) //判斷公里數(shù)
totalPrice = startPrice +(distance - 3)*perPrice + tax; //計(jì)算價(jià)錢
else
totalPrice = startPrice + tax;? ??
return totalPrice;
}
int main()
{
int moring = 9; //定義上午打車時(shí)間
int afternoon = 18; //定義下午打車時(shí)間
int distance = 12; //定義打車公里數(shù)
double allPrice = 0; //定義總費(fèi)用
allPrice = TaxiPrice(moring,distance) + TaxiPrice(afternoon,distance); //調(diào)用計(jì)算費(fèi)用的函數(shù)
printf("小明每天打車的總費(fèi)用是:%.2f\n",allPrice); //輸出
return 0;? ??
}