syntax error before '=' token

This is a discussion on syntax error before '=' token within the C Programming forums, part of the General Programming Boards category; Help! I don't know what's wrong... It keeps giving error message syntax error before '=' token But I'm sure nothing ...

  1. #1
    Registered User
    Join Date
    Feb 2010
    Posts
    30

    syntax error before '=' token

    Help! I don't know what's wrong...
    It keeps giving error message
    syntax error before '=' token
    But I'm sure nothing is wrong...

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    
    #define PI=3.14
    
    int main(void)
    {
        double vol,area,r,h;
        
        printf("radius is : ");
        scanf("%lf",&r);
        printf("height is : ");
        scanf("%lf",&h);
        
        vol=PI*r*r*h;
        area=2*PI*r*r+2*PI*r*h;
        
        printf("volume is: %g and area is: %g\n", vol,area);
        
        getch();
        return 0;
        }

  2. #2
    C++ Witch laserlight's Avatar
    Join Date
    Oct 2003
    Location
    Singapore
    Posts
    23,641
    This:
    Code:
    #define PI=3.14
    should probably be:
    Code:
    #define PI 3.14
    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
    Guest Sebastiani's Avatar
    Join Date
    Aug 2001
    Location
    Waterloo, Texas
    Posts
    5,708
    Quote Originally Posted by vsovereign View Post
    Help! I don't know what's wrong...
    It keeps giving error message

    But I'm sure nothing is wrong...

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    
    #define PI=3.14
    
    int main(void)
    {
        double vol,area,r,h;
        
        printf("radius is : ");
        scanf("%lf",&r);
        printf("height is : ");
        scanf("%lf",&h);
        
        vol=PI*r*r*h;
        area=2*PI*r*r+2*PI*r*h;
        
        printf("volume is: %g and area is: %g\n", vol,area);
        
        getch();
        return 0;
        }
    Remember, macro expansion is literal, so everywhere in you program that the expression "PI" appears is substituted with "=3.14".

  4. #4
    Registered User
    Join Date
    Feb 2010
    Posts
    30
    thank you!

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. what am I missing? (Program won't compile)
    By steals10304 in forum C Programming
    Replies: 3
    Last Post: 08-25-2009, 03:01 PM
  2. more then 100errors in header
    By hallo007 in forum Windows Programming
    Replies: 20
    Last Post: 05-13-2007, 08:26 AM
  3. Using VC Toolkit 2003
    By Noobwaker in forum Windows Programming
    Replies: 8
    Last Post: 03-13-2006, 06:33 AM
  4. Connecting to a mysql server and querying problem
    By Diod in forum C++ Programming
    Replies: 8
    Last Post: 02-13-2006, 09:33 AM
  5. Dikumud
    By maxorator in forum C++ Programming
    Replies: 1
    Last Post: 10-01-2005, 06:39 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21