运输公司对用户计算运输费用C语言109页

#include <stdio.h>
//d不能是整型 !!
/*s<250            无折扣   s<1
250<=s<500         0.02     1
500<=s<1000        0.05     2 3
1000<=s<2000       0.08     4 5 6 7
2000<=s<3000       0.10     8 9 10 11
3000<=s            0.15     12 13 14
*/
int main()
{
    //每千米货物基本运费p 距离s 货物重w 折扣d f总运费 f=p*w*s*(1-d)
    double p,w,d,f,s;
    int c;
    scanf("%lf,%lf,%lf",&p,&w,&s);
    if (s>=3000)
       c = 12;
    else
    {
        c = s/250;
        switch(c)
        {
            case 0:d = 0;break;
            case 1:d = 2;break;
            case 2:
            case 3:d = 5;break;
            case 4:
            case 5:
            case 6:
            case 7:d = 8;break;
            case 8:
            case 9:
            case 10:
            case 11:d=10;break;
            case 12:d=15;break;
            default:break;
        }
        
    }
    f = p*s*(1-d/100)*w;
        printf("%f",f);
        return 0;
    
 }

猜你喜欢

转载自www.cnblogs.com/LiQingXin/p/12761910.html