题目中的:
货物重量≤5公斤,快递费收3元
应该为
货物重量≤5公斤,快递费收3元/公斤
#include
int a[17]={-1,0,3,5,6,10,12,18,20,25,30,35,40,50,55,57,60};// 测试数据
int main()
{
int i=17;
int zhongliang;
float flg;
while(i)
{
i--;
//scanf("%d",&zhongliang);
zhongliang=a[i];
flg=0;
switch(zhongliang/5)
{
case 6:case 7:case 8:case 9: case 10:
flg += (float)(5*(zhongliang-30)); zhongliang=30;
case 4:
case 5: flg += (float)(4.5*(zhongliang-20));zhongliang=20;
case 2:
case 3: flg += (float)(4*(zhongliang-10)); zhongliang=10;
case 1: flg += (float)(3.5*(zhongliang-5)); zhongliang=5;
case 0: flg += (float)(3*zhongliang); break;
default: flg = -1;
}
if(flg>=0)
printf("%2d -- %0.2f \n",a[i],flg);
else
printf("%2d -- No! \n",a[i]);
}
//getch();
}