㈠ C語言編程:請編計程車計費程序
#include
"iostream"
using
namespace
std;
int
main()
{
int
index;
double
per;
double
qibu;
int
kilometre;
double
pay
=
0;
cout
<<"輸入里程數(公里):";
cin
>>
kilometre;
cout
<<"選擇車輛:1.桑塔納
2.夏利"<<endl;
cin>>index;
if(index==1)
{
per
=
2.7;
qibu
=
4;
}
else
{
per
=
2.1;
qibu=3;
}
if(kilometre>3)
pay
=
qibu
+
(kilometre-3)*per;
else
pay
=
qibu;
cout
<<"總價為:"<<pay<<endl;
return
0;
}
你也可以用結構數組來保存單價和起步費
㈡ 用C語言要寫,計程車收費,3公里內收5元,超3公里部分每公收1.2元。
#include<stdio.h>
intmain()
{
inta;
floatv;
scanf("%d",&a);
if(a<=3)v=5;
elsev=5+1.2*(v-3);
printf("%.1f ",v);
return0;
}