大神速來!5-14的綜合練習(xí),跑不出來,錯(cuò)在哪?
#include?<stdio.h> float?price(int?dictance,int?useTime) { ???int?startPrice?=?13; ???float?fuel?=?1; ???float?milePrice?=?2.3; ???float?totalPrice; ???while(useTime<5||useTime>=23) ???{ ???????if(useTime<0||useTime>24) ???????{ ???????????printf("%s\n","時(shí)間輸入有誤。"); ???????????return?0; ???????????break; ???????} ???????else ???????{ ???????????milePrice*=1.2; ???????????break; ???????} ???} ???if(distance<=3) ???{ ???????totalprice?=?startPrice+fuel; ???} ???else ???{ ???????totalPrice?=?startPrice+milePrice*(dictance-3)+fuel; ???} ???return?totalPrice; } int?main() { ???int?amTime?=?9; ???int?pmTime?=?18; ???int?distance?=?12; ???printf("小明上午打車的費(fèi)用是%f\n",price(distance,amTime)); ???printf("小明下午打車的費(fèi)用是%f\n",price(distance,pmTime)); ???printf("小明打車的總費(fèi)用是%f\n",price(distance,amTime)+price(distance,pmTime)); ???return?0; }
運(yùn)行結(jié)果如下:
/249/5642/CD9l/hello.c: In function 'price':
/249/5642/CD9l/hello.c:22:8: error: 'distance' undeclared (first use in this function)
? ? if(distance<=3)
? ? ? ?^
/249/5642/CD9l/hello.c:22:8: note: each undeclared identifier is reported only once for each function it appears in
/249/5642/CD9l/hello.c:24:9: error: 'totalprice' undeclared (first use in this function)
? ? ? ? totalprice = startPrice+fuel;
2016-02-21
小心使得萬年船
2016-02-20
原來是distance誤寫成dictance,同時(shí)totalPrice的P小寫成p了,太粗心!