【发布时间】:2015-03-22 18:19:56
【问题描述】:
我无法使此代码正常工作。我刚刚学习了这个内容(if else 语句),并且必须通过创建一个计算每个不同车辆的停车成本的程序来实现它。 c 用于汽车(每小时 2 美元),b 用于公共汽车(每小时 3 美元),t 用于卡车(每小时 4 美元)。这是在使用 dev-c++ 编译器的 c 编程中。
感谢所有反馈,提前感谢您!
#include <stdio.h>
//declaration
char parkingCharge (int pc);
int pc;
int h, total, c, b, t;
char v;
int main (void)
{
//statements
printf ("Enter type of vehicle (c for car, ");
printf ("b for bus, or t for truck): ");
scanf ("%c", &v);
printf ("How long did you park: ");
scanf ("%d", &h);
total = pc;
printf ("Your total is: %d", total);
return 0;
}
char parkingCharge (int pc)
{
//statements
if (v == c){
pc = 2 * h;
}
else if (v == b){
pc = 3 * h;
}
else if (v == t){
pc = 4 * h;
}
return total;
}
【问题讨论】:
-
parkingCharge 应该可能返回一个 int(速率和时间的乘积)
-
感谢您的回复!我不明白你的意思。我对编程相当陌生。 pc等于产品费率和时间,不是吗?
-
你甚至不打电话给
parkingCharge(),但如果你打电话了,你对变量的使用就无处不在了。