㈠ 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;
}