在下近日在学习C语言,做习题时发现了一个小问题。
这是一道关于货车载物收费的问题,大体上已经做出来了,但是在对基础收费即p进行输入时,用scanf输入时发现无效,把p打印出来值依然没有任何变化。其代码已放在下面,有问题的scanf用黄色标记了。希望有大佬出来帮忙解决一下。谢谢大家。
由于刚才在手机客户端上发现无法看到颜色标记,我在那行代码后面加个中文的注释来标明位置。
#include<stdio.h>
void main()//Transport fee
{
double p, w, s, d, f;//p is basic fee of one ton per kilometer, w means weight, s is distance, d si discount, f is total fee.
int i = 0;
puts("Please set the basic pay for the transportation: ");
scanf("%ld", &p);/为什么这个输入在运行时无法实现,打印出p发现仍是初始值0?
printf("%lf\n",p);
puts("Please input the weigth of the cargo and the distance of transportation in order: ");
scanf("%lf%lf", &w, &s);
if(s > 0&&s < 250)
{
d = 0;
i = 1;
}
if(s >= 250&&s < 500)
{
d = 0.02;
i = 2;
}
if(s >= 500&&