求大神幫看程序,為什么我的程序不能得到小數(shù)部分?
自己手算結(jié)果是34.7 34.7 ?69,.4
但是運(yùn)行的結(jié)果是34 34 68 ?
不知道是哪里弄錯(cuò)了 幫忙看看~~~~~~
#include <stdio.h>
int getdayprice(int h,int t)
? {
? ? float price;
? ? if(h<3)
? ? ? { price=14;}
? ? ??
? ? else?
? ? ?{if(t>=23||t<5)
? ? ? ? ?{price=(h-3)*2.3*1.2+14;}
? ? ? ? ?
? ? ? else
? ? ? ? ?{price=(h-3)*2.3+14;}
? ? ?}
? ? return price;
? }
? ?
int main()
{ ? float taxifee1,taxifee2,sum;
? ? taxifee1=getdayprice(12,9);
? ? printf("小明每天早上的打車(chē)費(fèi)用是%f\n",taxifee1);
? ? taxifee2=getdayprice(12,18);
? ? ?printf("小明每天下午的打車(chē)費(fèi)用是%f\n",taxifee2);
? ? sum=taxifee1+taxifee2;
? ? ?printf("小明每天總共的打車(chē)總費(fèi)用是%f\n",sum);
? ? return 0;
}
2016-02-25
把函數(shù)?getdayprice的返回類(lèi)型改為 float ,還有你的思路有點(diǎn)問(wèn)題喔,我覺(jué)得并不需要把小明打車(chē)的時(shí)間分為早上和中午來(lái)算呀,直接弄位從早上9點(diǎn)到下午18點(diǎn)的范圍就行了呀