C语言编程:某市不同车牌的出租车3公里的起步价和计费分别为:夏利7元,3公里以外,2.1元⼀公里;

2025年03月01日 12:17
有1个网友回答
网友(1):

#include
main()
{
int type;
float distance,pay;
printf("Enter the type and the distance:");
scanf("%d%f",&type,&distance);

if(type==1)//夏利

{
if(distance<=3.0) pay=7.0;
else pay=7.0+(distance-3.0)*2.1;
printf("The pay is:%.2f\n",pay);
}

else
if (type==2)//富康

{
if(distance<=3.0) pay=8.0;
else pay=8.0+(distance-3.0)*2.4;
printf("The pay is:%.2f\n",pay);
}

else

if(type==3)//桑塔纳
{

if(distance<=3.0) pay=9.0;
else pay=9.0+(distance-3.0)*2.7;
printf("The pay is:%.2f\n",pay);
}

else printf("there is wrong,please enter again:\n");
}