大米摇一摇
2018-10-24 14:38
#include <stdio.h>
int fee(int mile,int time)
{
float a = 2.3;
int b = 13;
float cost;
if(mile>3)
{
if(23 <= time < 5)
{
cost = b +(mile-3)*2.3*1.2+1;
}
else (time<23 || time>5)
{
cost = b +(mile-3)*2.3+1;
}
}
else(mile <= 3)
{
cost = b;
}
return cost;
}
int main()
{
float sum = fee(12,9) + fee(12,18);
printf("小明每天打车的总费用为%.2f元",sum);
return 0;
}
if(23 <= time < 5)
{
cost = b +(mile-3)*2.3*1.2+1;
}
你的这一段有问题 5不应该比23大
所以应该改成 if(time >= 23 && time <5)
else后面可以不接东西的
可以是这样子#include <stdio.h>
int fee(int mile,int time)
{
float a = 2.3;
int b = 13;
float cost;
if(mile>3)
{
if(23 <= time < 5)
{
cost = b +(mile-3)*2.3*1.2+1;
}
else
{
cost = b +(mile-3)*2.3+1;
}
}
else
{
cost = b;
}
return cost;
}
int main()
{
float sum = fee(12,9) + fee(12,18);
printf("小明每天打车的总费用为%.2f元",sum);
return 0;
}
C语言入门
926025 学习 · 20793 问题
相似问题