NodeOS
2016-02-20 12:00
#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","时间输入有误。"); 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\n",price(distance,amTime)); printf("小明下午打车的费用是%f\n",price(distance,pmTime)); printf("小明打车的总费用是%f\n",price(distance,amTime)+price(distance,pmTime)); return 0; }
运行结果如下:
/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;
小心使得万年船
原来是distance误写成dictance,同时totalPrice的P小写成p了,太粗心!
C语言入门
926210 学习 · 20797 问题
相似问题