Syntax error before = sign

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • abrown07
    New Member
    • Jan 2010
    • 27

    Syntax error before = sign

    Code:
     
    
    double gravityFactor(double mass, double radius)
    {  
         
         double gf;
        
          gf=((mass/Me)/((radius/Re)*(radius/Re)));
         
          return gf;     
    }  
    
    double escapeVelocity(double mass, double radius)
    {
        
        double ev;
         
         ev=(sqrt((2*(G)*mass)/radius))/1000;
         
         return ev;    
    }
    I have syntax error before = sign in both functions?
  • jkmyoung
    Recognized Expert Top Contributor
    • Mar 2006
    • 2057

    #2
    What are the errors; can you post them?
    Have you defined constants, G, Me and Re somewhere else?

    Comment

    • abrown07
      New Member
      • Jan 2010
      • 27

      #3
      yes the constants have been defined before the main body of the program. Here is my entire program and the commented sections are just there to remind myself of what i still need to do with the program after i figure out this whole function thing.

      Code:
      #include <stdio.h>
      #include <math.h>
      #include <string.h>
      #include <stdlib.h>
      
      #define G = 6.667428e-11
      #define Me = 5.9736e24
      #define Re = 6371000
      
      double gravityFactor(double mass, double radius);
      double escapeVelocity(double mass, double radius);
      
      
      
      
      
      
      
      
      int main(void)
      {
           double mass, radius, gf, ev;
           int unit;
           
        //          char radius[10] = {3.3022e23, 4.8685e24, 5.9736e24, '7.3477e22', '6.4185e23',
      //            '1.8986e27', '5.6846e26', '8.6810e25', '1.0243e26',};
      //            
      //            char mass[10] = {'2439700', '6051800', '6371000', '1737100', '3396200', '71492000',
      //            '60268000', '25559000', '24764000'};
      //     
      
      
            printf("Select 1 for escape velocity and gravity factor.Select 2 to input values: ");
            scanf("%d", &unit);
            if(unit==1)  
            {
      
       //           fgets("%s", radius);
      //            gravityFactor=((mass[0]/5.9736e24)/((radius[0]/6371000)*(radius[0]/6371000)));
      //            
      //            printf("The gravity factor of Mercury is: %.2f\n", gravityFactor);
      //            
      //            
                 
                 
                 
            }  
                else if(unit==2)
                {
                   	
                    do
                    {
                        printf("Please input the mass of your stellar bodies: ");
                        scanf("%lf", &mass);
           
                        printf("Please indicate the radius of your stellar body: ");
                        scanf("%lf",&radius);
             
         				  
         				  
                        printf("The gravity factor of this stellar body is: %.2f\n", gf);
                       //  
      //                   double escapeVelocity(double m, double r);
      //                   
      //                   printf("The escape velocity of this stellar body is: %.2f km/s\n", ev);
      //   
      //                   printf("Please select 1 to calculate another planet. Press any number key to terminate.: ");
      //                   scanf("%d", &unit);
      //   
                    }while(unit==1);
                }
        
        return 0;
        
        
      }
      
      double gravityFactor(double mass, double radius)
      {       
         double gf;    
         gf =((mass/Me)/((radius/Re)*(radius/Re)));   
         return gf;     
      }  
      
      
      double escapeVelocity(double mass, double radius)
      {    
         double ev;     
         ev =(sqrt((2*(G)*mass)/radius))/1000;    
         return ev;    
      }
      this is what my compiler gives me

      assignment4.c: In function ‘gravityFactor’ :
      assignment4.c:8 1: error: syntax error before ‘=’ token
      assignment4.c:8 1: error: syntax error before ‘=’ token
      assignment4.c:8 1: error: syntax error before ‘=’ token
      assignment4.c: In function ‘escapeVelocity ’:
      assignment4.c:8 9: error: syntax error before ‘=’ token

      Comment

      • jkmyoung
        Recognized Expert Top Contributor
        • Mar 2006
        • 2057

        #4
        c doesn't understand numbers in the form 6.667428e-11.
        Convert them into floats or doubles.

        Comment

        • abrown07
          New Member
          • Jan 2010
          • 27

          #5
          this is not fix the problem. and it was accepting them as inputs and giving me the correct outputs before i tried defining them

          Comment

          • weaknessforcats
            Recognized Expert Expert
            • Mar 2007
            • 9214

            #6
            #define G = 6.667428e-11
            #define Me = 5.9736e24
            #define Re = 6371000
            G, Me and Re should be doubles rather than a #define value.

            That is, 6.667428e-11 is not a double. It is the value of a double.

            Comment

            Working...