Thread: Getting the following error: error C2059: syntax error : '=', can anyone help?

  1. #1
    Registered User skaldicpoet9's Avatar
    Join Date
    Dec 2007
    Posts
    15

    Getting the following error: error C2059: syntax error : '=', can anyone help?

    I am trying to define values for the variables "area" and "circ" but everytime I try to build the project I get this error:

    Code:
    error C2059: syntax error : '='
    Here is the code in question:

    Code:
    #include<stdio.h>
    #include<math.h>
    #define PI = 3.14159 
    
    int main()
    {
    	int var1, two = 2;
    	double radius, area, circ;
    	
    	printf("Program: Arithmetic Expressions\nAuthor: Stephen Haroldson\nEnter unsigned short int: ");
    	scanf("%d", &var1);
    	printf("The value of %d raised to the %d power is %f\n", two, var1, pow(two, var1));
    	printf("Enter unsigned short int: ");
    	scanf("%1f", &radius);
    
    	area = PI * radius * radius;
    	circ = 2 * PI * radius;
    
    	printf("A circle with a radius %d has a circumference of %f and an area of %f\n", radius, circ, area);
            return 0;
    }
    If anyone can give me any suggestions I would appreciate it greatly. Thanks.

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    28,413
    A macro definition is not a normal assignment, hence this:
    Code:
    #define PI = 3.14159
    should be:
    Code:
    #define PI 3.14159
    Quote Originally Posted by Bjarne Stroustrup (2000-10-14)
    I get maybe two dozen requests for help with some sort of programming or design problem every day. Most have more sense than to send me hundreds of lines of code. If they do, I ask them to find the smallest example that exhibits the problem and send me that. Mostly, they then find the error themselves. "Finding the smallest program that demonstrates the error" is a powerful debugging tool.
    Look up a C++ Reference and learn How To Ask Questions The Smart Way

  3. #3
    Registered User TheBigH's Avatar
    Join Date
    May 2010
    Location
    Melbourne, Australia
    Posts
    426
    Also check your types in your printf statements. %d and %lf do not go with doubles.
    Code:
    while(!asleep) {
       sheep++;
    }

  4. #4
    Registered User
    Join Date
    Jul 2011
    Posts
    3
    may be #define with no need for "="

  5. #5
    Registered User skaldicpoet9's Avatar
    Join Date
    Dec 2007
    Posts
    15
    Ah, I see. Thanks for the information. I knew it had to do something with the preprocessor statements.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. error c2059 'constant' if else statements
    By kt12327 in forum C++ Programming
    Replies: 4
    Last Post: 10-01-2010, 07:02 PM
  2. error C2061: syntax error : identifier
    By maninboots in forum C++ Programming
    Replies: 4
    Last Post: 07-02-2009, 05:40 AM
  3. error C2059: syntax error : '('
    By JOCAAN in forum C Programming
    Replies: 1
    Last Post: 11-30-2008, 08:41 AM
  4. GCC compiler giving syntax error before 'double' error
    By dragonmint in forum Linux Programming
    Replies: 4
    Last Post: 06-02-2007, 05:38 PM
  5. Template Class and C2059 Error
    By flamingwitch in forum C++ Programming
    Replies: 6
    Last Post: 08-16-2004, 01:09 PM