简单的C题目

来源:百度知道 编辑:UC知道 时间:2024/09/28 06:10:43
某市不同车牌的出租车,3公里的起步价和计费分别为:夏利为7元,3公里以外2.1元/公里;富康8元,3公里以外2.4元/公里;桑塔纳9元,3公里以外2.7元/公里。编程:从键盘输入乘车的车型及行车公里数输出应付车资。

这种问题用选择结构就能做出来

#include<stdio.h>
main()
{
int num;
double f,cost;
printf("Plese select the type from xia(1),huk(2),stn(3),and input the nunber:\n");
scanf("%d",&num);
if(num==1)
{
printf("Plese input the distance:");
scanf("%lf",&f);
if(f<=3)
cost=7.0;
else cost=7.0+2.1*(f-3.0);
}
if(num==2)
{
printf("Plese input the distance:");
scanf("%lf",&f);
if(f<=3)
cost=8.0;
else cost=8.0+2.4*(f-3.0);
}
if(num==3)
{
printf("Plese input the distance:");
scanf("%lf",&f);
if(f<=3)
cost=9.0;
else cost=9.0+2.7*(f-3.0);
}

printf("The distance is %lf\nThe cost is %lf\n",f,cost);
}