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