Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted!
- The problem statement, all variables and given/known data:
When the code is run only the first loop is utilized and it skips the following when it should move on after the first loop commands are not met
-
Relevant commands, code, scripts, algorithms:
while loop, else if -
The attempts at a solution (include all code and scripts):
/*
*File: circles_solutions.cpp
*Created by: Robert Marsch
*Created on: 2/3/2014
*Synopsis: To input the coordinates of a circle and radii of three circles and *report the location of the query point relative to the circles.
*/
#include <iostream>
#include <cmath>
#include <cstdlib>
using namespace std;
int main()
{
int xa, xb, xc, xq, xy, ya, yb, yc, yq, ra, rb, rc;
int distancex1, distancey1, distancex2, distancey2, distancex3, distancey3;
int d1, d2, d3;
int k;
cout << "Enter x and y coordinates of circle A (2 values): ";
cin >> xa >> xb;
cout<< "Enter radius of circle A: ";
cin >> ra;
cout << "Enter x and y coordinates of circle B (2 values): ";
cin >> xb>> yb;
cout << "Enter radius of circle B: ";
cin >> rb;
cout << "Enter x and y coordinates of circle C (2 values): ";
cin >> xc >> yc;
cout << "Enter radius of circle C: ";
cin >> rc;
cout << "Enter x and y coordinate of query point (2 values): ";
cin >> xq >> yq;
distancex1 = (xq - xa);
distancey1 = (yq - ya);
distancex2 = (xq - xb);
distancey2 = (yq - yb);
distancex3 = (xq - xc);
distancey3 = (yq - yc);
d1 = sqrt(pow(distancex1,2)+pow(distancey1,2));
d2 = sqrt(pow(distancex2,2)+pow(distancey2,2));
d3 = sqrt(pow(distancex3,2)+pow(distancey3,2));
while (int k=1)
if(d1 && d2 && d3 <= ra && rb && rc)
{
cerr << "Circles A B and C contain point (" << xq << " ," << yq << "). " << endl;
exit (10);
}
else if (d1 && d3 <= ra && rc && d2 >= rb)
{
cerr << "Circles A and C contain point (" << xq << " ," << yq << "). " << endl;
exit(20);
}
else if (d3 >= rc && d2 && d2 <= ra && rb)
{
cerr << "Circles A and B contain point (" << xq << " ," << yq << "). " << endl;
exit(30);
}
else if (d1 >= ra && d2 <= rb && d3 <= rc)
{
cerr << "Circles B and C contain point (" << xq << " ," << yq << "). " << endl;
exit(40);
}
else if (d2 && d3 >= rb && rc && d1 <= ra)
{
cerr << "Circle A contains point (" << xq << " ," << yq << "). " << endl;
exit(50);
}
else if (d1 && d3 >= ra && rc && d2 <= rb)
{
cerr << "Circle B contains point (" << xq << " ," << yq << "). " << endl;
exit(60);
}
else if (d1 && d3 >= ra && rc && d2 <= rb)
{
cerr << "Circle C contains point (" << xq << " ," << yq << "). " << endl;
exit(70);
}
else if (d1 && d2 && d3 >= ra && rb && rc)
{
cerr << "No circle contains point (" << xq << " ," << yq << "). " << endl;
exit(80);
}
return 0;
}
- Complete Name of School (University), City (State), Country, Name of Professor, and Course Number (Link to Course):
Ohio State, Columbus, OH, USA, Sharief, CSE1222
Note: Without school/professor/course information, you will be banned if you post here! You must complete the entire template (not just parts of it).