我的結(jié)果是77.68,大神看看···所以正確結(jié)果到底是?
#include <stdio.h>
double c;
double cost(int t ,double d)
{
? ? double p;
? ? if(23<=t<=24||0<=t<5)
? ? {
? ? ? ? p=2.3*1.2;
? ? }
? ? else
? ? {
? ? ? ? p=2.3;
? ? }
? ? if(d<=3)
? ? {
? ? ? ? c=13;
? ? ? ? return c+1;
? ? }
? ? else
? ? {
? ? ? ? c=13+(d-3)*p;
? ? ? ? return c+1;
? ? }
? ??
}
int main()
{
? ? double c=cost(9,12)+cost(18,12);
? ? printf("小明每天打車的總費(fèi)用為%f元",c);
? ? return 0;
}
2017-03-13
69.4
2017-02-07
?將 if(23<=t<=24||0<=t<5)改成t>=23&&t<=24||t>=0&&t<5結(jié)果就正確啦,&&的優(yōu)先級比||高,所以不用擔(dān)心,會(huì)先運(yùn)算完與再運(yùn)算或的。
2017-02-04
#include<stdio.h>
float Pay(int time,int dis)
{
float pay;
if(time>=23||time<5)
{
? pay=14+(dis-3)*2.3*1.2;
}
else
{
pay=14+(dis-3)*2.3;
}
return pay;
}
int main()
{
printf("小明打車的總費(fèi)用是%f元\n",Pay(9,12)+Pay(18,12));
return 0;
}