這個(gè)代碼該怎么改???謝謝!
#include <stdio.h>
float cost(int time,int mile)
{
? ? float money;
? ? if(mile<=3)
? ? {
? ? ? ? money=14;
? ? ? ? printf("打車費(fèi)用為14元");
? ? else
? ? {
? ? ? ? if(time>=23||time<5)
? ? ? ? {
? ? ? ? ? ? money=13+2.3*1.2*(mile-3)+1;
? ? ? ? ? ? printf("打車費(fèi)用為%.1f元",money);
? ? ? ??
? ? ? ? }
? ??
? ? ? ? else
? ? ? ? {
? ? ? ? ? ? money=13+2.3*(mile-3)+1;
? ? ? ? ? ? printf("打車費(fèi)用為%.1f元",money);
? ? ? ? }
? ? }
? ? return money;
}
int main()
{
? ? float totalMoney=cost(9,12)+total(6,12);
? ? printf("打車費(fèi)用為%.1f元\n",totalMoney);
? ? return 0;
}
2015-08-04
#include <stdio.h>
float cost(int time,int mile);//這里最好聲明一下
float cost(int time,int mile)
{
? ? float money;
? ? if(mile<=3)
? ? {
? ? ? ? money=14;
? ? ? ? printf("打車費(fèi)用為14元");
//少了一個(gè)括號(hào)
}
? ? else
? ? {
? ? ? ? if(time>=23||time<5)
? ? ? ? {
? ? ? ? ? ? money=13+2.3*1.2*(mile-3)+1;
? ? ? ? ? ? printf("打車費(fèi)用為%.1f元",money);//逗號(hào)要英文的
? ? ? ? }
? ? ? ? else
? ? ? ? {
? ? ? ? ? ? money=13+2.3*(mile-3)+1;
? ? ? ? ? ? printf("打車費(fèi)用為%.1f元",money);
? ? ? ? }
? ? }
? ? return money;
}
int main()
{
? ? float totalMoney=cost(9,12)+cost(6,12);
//float totalMoney=cost(9,12)+total(6,12);total是????
? ? printf("打車費(fèi)用為%.1f元\n",totalMoney);
? ? return 0;
}
2015-08-04
#include <stdio.h>
?
float cost(int time,int mile)
{
??? float money;
??? if(mile<=3)
??? {
??????? money=14;
??????? printf("打車費(fèi)用為14元");
??? }
??? else? if(time>=23||time<5)
??????? {
??????????? money=13+2.3*1.2*(mile-3)+1;
??????????? printf("打車費(fèi)用為%.1f元\n",money);
??????? }
??????? else
??????? {
??????????? money=13+2.3*(mile-3)+1;
??????????? printf("打車費(fèi)用為%.1f元\n",money);
??????? }
?
??? return money;
}
int main()
{
??? float totalMoney=cost(9,12)+cost(6,12);
??? printf("打車費(fèi)用為%.1f元\n",totalMoney);
??? return 0;
}