C++ btw.
So basically, I ask the user for the center points and radii of three circles. Then ask for a quary point. I need to write a program as to see whether the quary point is in circle A, B, C, a combination of the three, or in no circle whatsoever. I have an .exe file that I'm comparing my solutions to, but I don't seem to output the right answer. Could anyone help me? emotion_facepalm
/*
Synopsis:
This program reads in three circles and a query point
and reports which circles contain the query point.
*/
#include
#include
using namespace std;
int main()
{
// Variable declarations
double x1; // x coordinate of circle A
double y1; // y coordinate of circle A
double rA; // radius of circle A
double x2; // x coordinate of circle B
double y2; // y coordinate of circle B
double rB; // radius of circle B
double x3; // x coordinate of circle C
double y3; // y coordinate of circle C
double rC; // radius of circle C
double Q1; // x coordinate of query point
double Q2; // y coordinate of query point
double dxA(Q1-x1); // dx for circle A
double dyA(Q2-y1); // dy for circle A
double dxB(Q1-x2); // dx for circle B
double dyB(Q2-y2); // dy for circle B
double dxC(Q1-x3); // dx for circle C
double dyC(Q2-y3); // dy for circle C
// Prompt and read in circle A center coordinates
cout << "Enter x and y coordinates of circle A (2 values): ";
cin >> x1 >> y1;
// Prompt and read in circle A radius
cout << "Enter radius of circle A: ";
cin >> rA;
// Prompt and read in circle B center coordinates
cout << "Enter x and y coordinates of circle B (2 values): ";
cin >> x2 >> y2;
// Prompt and read in circle B radius
cout << "Enter radius of circle B: ";
cin >> rB;
// Prompt and read in circle C center coordinates
cout << "Enter x and y coordinates of circle C (2 values): ";
cin >> x3 >> y3;
// Prompt and read in circle C radius
cout << "Enter radius of circle C: ";
cin >> rC;
// Prompt and read in query point
cout << "Enter x and y coordinates of query point (2 values): ";
cin >> Q1 >> Q2;
// Determine location of query point relative to the circles
if (sqrt(dxA*dxA + dyA*dyA) <= rA)
{
if (sqrt(dxB*dxB + dyB*dyB) <= rB)
{
if (sqrt(dxC*dxC + dyC*dyC) <= rC)
{ cout << "Circles A, B and C contain point (" << Q1 << "," << Q2 << ")." << endl; }
else
{ cout << "Circles A and B contain point (" << Q1 << "," << Q2 << ")." << endl; }
}
else
{
if (sqrt(dxC*dxC + dyC*dyC) <= rC)
{ cout << "Circles A and C contain point (" << Q1 << "," << Q2 << ")." << endl; }
else
{ cout << "Circles A contains point (" << Q1 << "," << Q2 << ")." << endl; }
}
}
else if (sqrt(dxB*dxB + dyB*dyB) <= rB)
{
if (sqrt(dxC*dxC + dyC*dyC) <= rC)
{ cout << "Circles B and C contain point (" << Q1 << "," << Q2 << ")." << endl; }
else
{ cout << "Circle B contains point (" << Q1 << "," << Q2 << ")." << endl; }
}
else
{
if (sqrt(dxC*dxC + dyC*dyC) <= rC)
{ cout << "Circle C contains point (" << Q1 << "," << Q2 << ")." << endl; }
else
{ cout << "No circle contains point (" << Q1 << "," << Q2 << ")." << endl; }
}
return 0;
}