错误C2059:语法错误:' ='

时间:2014-09-17 03:54:26

标签: visual-studio

我一直得到两个语法错误,但我无法弄清楚原因。有人可以请帮我弄清楚出了什么问题,以及为什么我一直得到这些语法错误

shipping.c<61> : error C2059: syntax error : '='
shipping.c<70> : error C2059: syntax error : '='

这是我的错误所在的代码:

/ *请勿复制* /

#include <stdio.h>  
#include <math.h> 
#define PI = 3.14159
#define PACKING_DENSITY = 0.59

/ *函数原型* /

double bearing(double radius, double diameter);

double actual_weight(double density, double pound);

int shipping_weight(double actualWeight, double roundingFix);

double cost_per_box(int shippingWeight, double shippingRate);


int
main(void)
{

/ *给出变量名称* /

double width;
double height;
double depth;
double diameter;
double density;
double shippingRate;
double costPerBox;
double radius;

/ *调用变量* /

printf("Enter width %d\n");
scanf("%lf", &width);
printf("Enter height %d\n");
scanf("%lf", &height);
printf("Enter depth %d\n");
scanf("%lf", &depth);
printf("Enter diameter %d\n");
scanf("%lf", &diameter);
printf("Enter density %d\n");
scanf("%lf", &density);
printf("Enter shipping rate %d\n");
scanf("%lf", &shippingRate);

/ *返回答案* /

printf("Bearings = %f\n", bearing);
printf("Shipping weight = %f\n", shipping_weight);
printf("Shipping cost per box = %f\n", cost_per_box);

return(0);

}

/ *计算轴承* /

double
bearing(double radius, double diameter)
{   
radius = diameter / 2;

return((4 / 3) * pow(radius, 3) *PI);
}

/ *实际重量的计算* /

double 
actual_weight(double density, double pound)
{
pound = 2.20464; /* <=conversion */

return(density * PACKING_DENSITY * pound); 

}

/ *运输重量的计算* /

int
shipping_weight(double actualWeight, double roundingFix)
{
roundingFix = .9;

return(actualWeight + roundingFix);

}

/ *计算每箱成本* /

double 
cost_per_box(int shippingWeight, double shippingRate)
{

return(shippingWeight * shippingRate);

}

1 个答案:

答案 0 :(得分:0)

您将PI宏定义为

#define PI = 3.14159

表示PI的每次出现都会被= 3.14159取代。例如这个

return((4 / 3) * pow(radius, 3) *PI);

将变成这个

return((4 / 3) * pow(radius, 3) * = 3.14159);

这没有任何意义。 (请注意,在这种情况下,令牌不会连接,即*后跟=不会形成*=运算符。

为什么将=包含在PI的替换文字中?同样的问题适用于

#define PACKING_DENSITY = 0.59

=在那里做什么?