Return function problem

I need to somehow get the center point of an object using this code,

1
2
3
4
 
double Center_x, Center_y;
    return Center_x = (p1x+p2x+p3x)/3;
    return Center_y = (p1y+p2y+p3y)/3; 


However, I Dont know how to get the y variable to return as the cout looks like this (x,) (x being arbitrary)
the first return exits the function, you can't return 2 values without somehow combining the values in a structure.

Of course you can use a global variable.
@SamuelAdams
I still don't know how I would use a global variable to return an (x,y)

my cout in main looks like this
 
cout<< "The center Point is: ("<<obj.getCenterPoint()<<",)"<<endl;


using still returns only one value.
1
2
Center= (Center_x, Center_y);
   return Center;
Last edited on
Declaring variables should be one of the first things you learn. Simply move your variables outside your main function under the #include's.

https://www.tutorialspoint.com/cplusplus/cpp_variable_scope.htm
Last edited on
Topic archived. No new replies allowed.