注册 登录
编程论坛 C语言论坛

求助!请问各位大大 我的语法哪里出错了

临风独舞翩跹 发布于 2020-08-30 19:52, 1071 次点击
只有本站会员才能查看附件,请 登录



我的程序
#include<stdio.h>
void main()
{
    int p,w,s;
    float d,f;
    printf("请输入基本运费,货物重量,运输距离.\n");
    scanf("%d%d%d",&p,&w,&s);
    f=p*w*s*(1-d);
    switch(0<s<=3000)
    {
    case s<250:printf("总运费为\n",p*w*s);break;
    case 250<=s<500:printf("总运费为\n",p*w*s*(1-0.02));break;
    case 500<=s<1000:printf("总运费为\n",p*w*s*(1-0.05));break;
    case 1000<=s<2000:printf("总运费为\n",p*w*s*(1-0.08));break;
    case 2000<=s<3000:printf("总运费为\n",p*w*s*(1-0.1));break;
    case 3000=s:printf("总运费为\n",p*w*s*(1-0.15));break;
    default:printf("input error\n");
    }
}   
1 回复
#2
纯蓝之刃2020-08-30 21:13
程序代码:
#include<stdio.h>

int main()
{
    int p,w,s,num,type;
    float f=0;
    printf("请输入基本运费,货物重量,运输距离.\n");
    scanf("%d%d%d",&p,&w,&s);
    type=s/250;
    switch(type)
    {
    default:
        num=s-250*12;
        f+=p*w*num*(1-0.15);
    case 11:
    case 10:
    case 9:
    case 8:
        num=s>=250*12?(3000-2000):(s-250*8);
        f+=p*w*num*(1-0.10);
    case 7:
    case 6:
    case 5:
    case 4:
        num=s>=250*8?(2000-1000):(s-250*4);
        f+=p*w*num*(1-0.08);
    case 3:
    case 2:
        num=s>=250*4?(1000-500):(s-250*2);
        f+=p*w*num*(1-0.05);
    case 1:
        num=s>=250*2?(500-250):(s-250);
        f+=p*w*num*(1-0.02);
    case 0:
        num=s>=250?250:s;
        f+=p*w*num;
        break;
    }
    printf("总运费为%f\n",f);

    return 0;
}

我认为应该是这样,不过最好有个示例验证一下。
1