打车计费
2 公里内起步 7 元
每公里 1.8 元计费。
超过 10 公里,超过部分按每公里 2.1 元
超过 100 公里,超过部分按每公里 3 元
(使用switch函数)
#include <stdio.h>
int main()
{
int n;
float s = 0;
scanf("%d",&n);
switch(n/10)
{
case 0:
if(n<=2)
s = 7;
else
{
s = 7 + (n-2)*1.8;
}
break;
case 1:
case 2:
case 3:
case 4:
case 5:
case 6:
case 7:
case 8:
case 9:
s = 7 + 8*1.8 + (n-10)*2.1;
break;
default:
s = 7 + 8*1.8 + 90*2.1 +(n-100)*3;
break;
}
printf("%f",s);
return 0;
}