#include<iostream>
#include<cmath>
usingnamespace std;
double distance=0;
struct Point {
int x;
int y;
};
struct Circle {
Point centre;
int radius;
};
void print_circle(const Circle& circle)
{
cout<<"Circle #1"<<endl;
cout<<"The Centre is: ("<<circle.centre.x<<", "<<circle.centre.y<<")"<<endl;
cout<<"The Radius is: "<<circle.radius<<endl;
}
double circle_distance(const Circle& circle1,const Circle& circle2)
{
double a, b, c;
a=abs(circle1.centre.y-circle1.centre.x);
b=abs(circle2.centre.y-circle2.centre.x);
c=pow(a,2)+pow(b,2);
distance=sqrt(c);
return distance;
}
int circle_test(const Circle& circle1, const Circle& circle2)
{
int x;
x=abs(circle2.radius-circle1.radius);
if (circle1.centre.x==circle2.centre.x&&circle1.centre.y==circle2.centre.y&&circle1.radius==circle2.radius)
return 0;
if (distance<x)
return 1;
if (distance>(circle2.radius+circle1.radius))
return 2;
elsereturn 3;
}
The error is that "distance" is undefined, but I thought that since I put it at the top it would count as a global variable and it can be used anywhere in the program...? Any help would be great.
Also, in the last function, what is the syntax to be used to tell the program to perform various actions depending on whether the function returned 0,1,2 or 3?
distance is not undefined. In opposite it's defined more than once. You have a name clash with std::distance(). That's an example why usingnamespace std; is evil
Also, in the last function, what is the syntax to be used to tell the program to perform various actions depending on whether the function returned 0,1,2 or 3?