error: expected identifier

Sep 29, 2011 at 5:34pm
this is my program

1 #include <math.h>
2 #include <stdio.h>
3
4 int main(int argc, char* argv[]){
5 float r;
6 float z;
7 float M_PI;
8 printf("Please enter a radius value:");
9 scanf("%f", &r);
10 z = M_PI * r * r;
11 printf("The area of the circle %f\n", z);
12
13 return 0;
14 }



when I compile it, I get this error

p20.c: In function ‘main’:
p20.c::7 error: expected identifier or ‘(’ before numeric constant

what does this mean? and how do i fix it?
Sep 29, 2011 at 5:53pm
M_PI is a constant #defined in one of those header files

So after the pre-processor has been through it you code looks something like this

float 3.14159;

If you want to declare a variable to be pi then put

float pi = M_PI;

Alternatively, just use M_PI wherever you need pi in your calculation
Topic archived. No new replies allowed.