請各位朋友們看看我這個問題出在哪里?。?/h1>
#include <stdio.h>
int main()
{
? ? float? taxicost(int Time,int distance);
? ? int a;
? ? printf("please enter Time and distance")
? ? scanf("%d,%d",&Time,&distance);
? ? a=taxicost(Time,distance);
? ? printf ("小明每天打車的總費用是%f元",2*a);
? ? return 0;
}
float? taxicost(int Time,int distance)
{
? ??
if (distance<=3)
{
? ? taxicost=14;
}
else if(5<=Time<23;distance>3)
{
? ? taxicost=(distance-3)*2.3+14;
}
else if(23<=Time<24||24<=Time<5;distance>3)
{
? ? taxicost=(distance-3)*2.3*1.2+14;
}
return taxicost;
}
#include <stdio.h>
int main()
{
? ? float? taxicost(int Time,int distance);
? ? int a;
? ? printf("please enter Time and distance")
? ? scanf("%d,%d",&Time,&distance);
? ? a=taxicost(Time,distance);
? ? printf ("小明每天打車的總費用是%f元",2*a);
? ? return 0;
}
float? taxicost(int Time,int distance)
{
? ??
if (distance<=3)
{
? ? taxicost=14;
}
else if(5<=Time<23;distance>3)
{
? ? taxicost=(distance-3)*2.3+14;
}
else if(23<=Time<24||24<=Time<5;distance>3)
{
? ? taxicost=(distance-3)*2.3*1.2+14;
}
return taxicost;
}
2021-07-28
被調用函數要在主函數前面
主函數里面的? ?float? taxicost(int Time,int distance);? ? 可以省略啊
主函數的Time 和 distence 沒有聲明
變量a的類型應該是float類型
scanf("%d,%d",&Time,&distance); 用得不對啊,建議定義變量的時候直接賦值
taxicost函數里面的taxicost為變量需要聲明
else if(5<=Time<23;distance>3) 中 “;”改成“&&”
else if(23<=Time<24||24<=Time<5;distance>3)? ? 同上
24<=Time<5 Time是定義的變量不會遵循時間的24小時循環 改成“Time>0&&(Time<5||Time>=23)”