Originally Posted by

**sing0**
hello,

I'm new with c programming and...

I'm trying to program a function which should perform the mathematical ditstance formula

but I 'm getting this error: found '{' at file scope (missing function header?

this is the code that I wrote

Code:

#include <stdio.h>
#include <math.h>
float distance(float x1, float x2, float y1, float y2);
{
float a=0 ,b=0 ,c=0, d=0 e=0;
a= x2 -x1;
b= y2 -y1;
c = pow(a,2);
d = pow(b,2);
c+d=e
return sqrt(e);
}
int main()
{
x1=2; x2=4; y1=3; y2=6;
printf("%lf\n",distance(x1,x2,y1,y2);
return 0;
}

what do I do wrong?

thenks for helping..

So many basic problems in your code

dude so many i count so many

1.....

Code:

float distance(float x1, float x2, float y1, float y2); // there is no need of ; here remove it

2.....

Code:

float a=0 ,b=0 ,c=0, d=0 e=0; // there is a need of , between d and e

3.....

Code:

c+d=e // dont know what you want to do it here may be you are doing e = c + d
e = c + d;

4.....

Code:

c+d=e // need ; after the statement
e = c + d;

5.....

Code:

float x1=2; x2=4; y1=3; y2=6; // here you need coma instead of semicolon
float x1=2, x2=4, y1=3, y2=6; // here you need coma instead of semicolon

6.....

Code:

printf("%f\n",distance(x1,x2,y1,y2); // missing ) parenthesis
printf("%f\n",distance(x1,x2,y1,y2));