求不同地区快递费用 educoder C语言

#include<stdio.h>

    int main(void)

    {  

      /*********Begin*********/

      int area;

      float weight,Price;

      scanf("%d,%f",area,weight);

      if(area=0){

          if(weight<=1)

      {Price=10;}

      else{

          Price=10+(weight-1)*3;}

          printf("Price:%.2f\n,Price");

      }

      else if(area=1){

          if(weight<=1)

      {Price=10;}

      else

      {Price=10+(weight-1)*4;}

      printf("Price:%.2f\n,Price");

      }

      else if(area=2){

          if(weight<=1)

      {Price=15;}

      else

      {Price=15+(weight-1)*5;}

      printf("Price:%.2f\n,Price");

      }

      else if(area=3){

          if(weight<=1)

      {Price=15;}

      else

      {Price=15+(weight-1)*6.5;}

      printf("Price:%.2f\n,Price");

      }

      else if(area=4){

          if(weight<=1)

      {Price=15;}

      else

      {Price=15+(weight-1)*10;}

      printf("Price:%.2f\n,Price");

      }

        else{

          printf("Error in Area\nPrice:0.00");

      }

      /*********End**********/ 

       return 0;

    }

不知道哪里错啦

由于您没有提出你的问题点,所以我只能猜测是在 scanf 这里有问题,不建议写 "%d,%f",因为这样你在输入的时候必须输入 0,1.1。建议你把逗号换为空格,

#include<stdio.h>

int main(void) {

    /*********Begin*********/

    int area;

    float weight, Price;

    scanf("%d %f", &area, &weight);

    if (area == 0) {
        if (weight <= 1) { Price = 10; }

        else {
            Price = 10 + (weight - 1) * 3;
        }

        printf("Price:%.2f\n",Price);

    } else if (area == 1) {
        if (weight <= 1) { Price = 10; }

        else { Price = 10 + (weight - 1) * 4; }

        printf("Price:%.2f\ni",Price);

    } else if (area == 2) {
        if (weight <= 1) { Price = 15; }

        else { Price = 15 + (weight - 1) * 5; }

        printf("Price:%.2f\n",Price);

    } else if (area == 3) {
        if (weight <= 1) { Price = 15; }

        else { Price = 15 + (weight - 1) * 6.5; }

        printf("Price:%.2f\n",Price);

    } else if (area == 4) {
        if (weight <= 1) { Price = 15; }

        else { Price = 15 + (weight - 1) * 10; }

        printf("Price:%.2f\n",Price);

    } else {
        printf("Error in Area\nPrice:0.00");

    }

    /*********End**********/

    return 0;

}

简单的改了改,问题很多。

  1. 比较的时候应该使用 ==
  2. scanf 的时候,参数应该传一个地址,所以有些要加取地址符
  3. printf 的时候,参数要单独写出来

您好,我是有问必答小助手,您的问题已经有小伙伴解答了,您看下是否解决,可以追评进行沟通哦~

如果有您比较满意的答案 / 帮您提供解决思路的答案,可以点击【采纳】按钮,给回答的小伙伴一些鼓励哦~~

ps:问答VIP仅需29元,即可享受5次/月 有问必答服务,了解详情>>>https://vip.csdn.net/askvip?utm_source=1146287632