如何才能使该程序的距离部分起作用?

时间:2014-07-02 23:53:59

标签: c

/* Shipping Calculator:
Speedy Shipping company will ship your package based on how much it weighs
and how far you are sending the package.  They will only ship small
packages up to 10 pounds.  You need to have a program that will help you
determine how much they will charge.  

The charges are based on each 500 miles shipped.  They are not pro-rated,
i.e., 600 miles is the same charge as 900 miles, i.e.,  600 miles is counted
as 2 segments of 500 miles.     

Here is the table they gave you:

Package Weight                        Rate per 500 miles shipped
2 pounds or less                      $1.50
More than 2 but not more than 6       $3.70
More than 6 but not more than 10      $5.25
*/

#include <stdio.h>
#include <stdlib.h>

main() 
{
    double packageWeight, packageDistance, packagePrice; 

    printf("Enter the weight of the package: \n");
    scanf("%lf", &packageWeight);
    printf("The weight you have entered is %lf\n", packageWeight);

    if (packageWeight <= 2 )
        packagePrice == 1.50;

    if (2 <= packageWeight >= 6) 
            packagePrice == 3.70;

    if (6 <= packageWeight <= 10 )
            packagePrice == 5.25;


    printf("How far are you sending the package? \n");
    scanf("%lf", &packageDistance);
    printf("The distance you entered is %lf\n", packageDistance);       

    system("PAUSE");
}

2 个答案:

答案 0 :(得分:3)

您似乎错误输入了==而不是=

使用==进行比较,使用=进行分配。

你也在这个表达式上犯了一个语法错误(2&lt; = packageWeight&gt; = 6),正确的方法是(2&lt; = packageWeight)&amp;&amp; (packageWeight&gt; = 6)

答案 1 :(得分:0)

您可以更改以下句子:

packagePrice = x.xx;

==用于比较,而=用于分配变量