答案都是69.400002嗎?
#include <stdio.h>
float price;
float Price(int time, int distance)
{
if (distance <= 3){
price = 13;
}
else{
if (time >= 5 && time < 23){
price = 13 + (distance - 3)*2.3 + 1;
}
else{
price = 13 + (distance - 3)*2.3*1.2 + 1;
}
}
return price;
}
int main()
{
printf("小明每天打車的總費(fèi)用為:%f\n", Price(9, 12) + Price(18, 12));
return 0;
}
2019-08-02
我是69.400000emmmmm
2019-07-26
函數(shù)和變量定義為double就好了
2019-07-25
#include <stdio.h>
double fee(int n,int time)//n為公里數(shù)
{? ?
? ?double sum;
? ? if(n<=3)
? ? ? ? return 13;
? ? else
? ? {
? ? ? ?if(time>=23||time<5)
? ? ? ? sum=13+2.3*(n-3)+1;
? ? ? ?else
? ? ? ?{
? ? ? ? sum=13+2.3*1.2*(n-3)+1;
? ? ? ?}
? ? ? ? return sum;
? ? }
}
int main()
{
? ? printf("小明每天打車的總費(fèi)用:%0.2lf",fee(12,9)+fee(12,18));
? ? return 0;
}
2019-07-25
為什么我是77.68