1 /*B4-分支-04. 出租車計價(15) 2 *測試通過 3 */ 4 #include <stdio.h> 5 #include <stdlib.h> 6 7 float consume_mile;//裡程 8 int consume_time;//等待時間 9 int consume_all;//計費總額 10 11 void Mile(float mile) 12 { 13 if(mile<=3) 14 { 15 consume_mile=10;//起步價10元,3km 16 } 17 else 18 { 19 if(mile<=13)//裡程在3~13km之間 20 { 21 mile=mile-3;//超出3km部分 22 consume_mile=((int)(mile+0.5))*2+10; 23 } 24 else//裡程在13km之外 25 { 26 mile=mile-13;//超出13km的部分 27 consume_mile=((int)(mile+0.5))*3+30; 28 } 29 } 30 printf("consume_mile=%f\n",consume_mile);///////////////////////////////////////////////////////// 31 } 32 33 void Time(int time) 34 { 35 if(time<5) 36 { 37 consume_time=0; 38 } 39 else 40 { 41 if(time%5==0) 42 { 43 consume_time=(time/5)*2; 44 } 45 else 46 { 47 consume_time=(time/5+1)*2; 48 } 49 } 50 printf("consume_time=%i\n",consume_time);///////////////////////////////////////////////////////// 51 } 52 53 int main(void) 54 { 55 56 void Mile(float mile); 57 void Time(int time); 58 59 float mile; 60 int time; 61 62 scanf("%f %i",&mile,&time); 63 printf("輸入成功:mile=%f time=%i\n",mile,time);/////////////////////////////////////////////// 64 65 Mile(mile); 66 Time(time); 67 68 consume_all=(int)(consume_time+consume_mile+0.5); 69 70 printf("consume_all=%i\n",consume_all); 71 72 return 0; 73 }