I am trying to define a function in c++,
I wrote it in main function.
I am getting an error : a function-definition is not allowed here before ‘{’ token}I have defined it as following :

float distance(float x, float y, float pitch)
     {
      float r;  //local variable
      r = sqrt(x * x + y * y);
      Bangle = arctan2(pitch*(y/r) + x , pitch*(x/r) -y);
      return (cos(Bangle),sin(Bangle));
     }

I dont know what dose this means. Any sugestion

You can't define a function in a function in C++. (=nested function)
Bring it outside of the Main function and call it in Main if you wish.

you mean like this:

float distance(float x, float y, float pitch)
int main()
{
float r,x,y,Bangle,pitch;  
      r = sqrt(x * x + y * y);
      Bangle = atan2(pitch*(y/r) + x , pitch*(x/r) -y);
      return (cos(Bangle),sin(Bangle),pitch);


}
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.