這個為什么運行不行
include <stdio.h>
? float qhc(int t,int km)
? {
? float price;
? ? ??
? ? ? if(23<=t<=24||0<=t<=5&&km<=3)
? ? ? {
? ? ? ? ? price=13+1;
? ? ? ??
? ? ? }
? ? ? else if(23<=t<=24||0<=t<=5&&km>3)
? ? ? {
? ? ? ? ? price=(km-3)*2.76+1;
? ? ? ? ??
? ? ? }
? ? ? else if(5<t<23&&km<=3)
? ? ? {
? ? ? price=13+1;
? ? ? }
? ? ? else
? ? ? {
? ? ? ? ? price=(km-3)*2.3+1;
? ? ? ? ??
? ? ? }
? ? ? return 0;
? ? ??
? }
? int main()
? {
? int t,km;
? float jiage;
? ?t=9;
? ?km=6;
? jiage=qhc(24,6);
? printf("打車要多少錢%f\n",jiage);
? ?return 0;
? }
搜索
復制
2021-12-04
#include <stdio.h>
? float qhc(int t,int km)
? {
? ? ? float price;
? ? ? if(23<=t&&t<=24||0<=t&&t<=5&&km<=3)
? ? ? {
? ? ? ? ? price=13+1;
? ? ? }
? ? ? else if(23<=t&&t<=24||0<=t&&t<=5&&km>3)
? ? ? {
? ? ? ? ? //price=(km-3)*2.76+1;應該加上起步價
? ? ? ? ? ?price=13+(km-3)*2.76+1;
? ? ? }
? ? ? else if(5<t&&t<23&&km<=3)
? ? ? {
? ? ? price=13+1;
? ? ? }
? ? ? else
? ? ? {
? ? ? ? ? price=13+(km-3)*2.3+1;
? ? ? }
? ? ? //return 0;不能返回0,應該返回計算出的price的值
? ? ? return price;
? }
? int main()
? {
? int t,km;
? float jiage;
? ?//t=9;
? ?//km=6;t和km不用單獨賦值,直接在下面的賦值語句對應賦值就好
? //jiage=qhc(24,6);
//按你的思路來的話因為是來往共兩次,所以應該分開計算,就是要算兩次起步價,一次9點,一次18點。
? jiage=qhc(9,12)+qhc(18,12);
? printf("打車要多少錢%.2f\n",jiage);//我這里加了.2限制了一下小數(shù)點,也可以不加,沒什么影響
? ?return 0;
? }
/*文中注釋起來的地方都是有問題的,然后我進行了修改,這是修改后的代碼*/