the main idea of the program is this
first of all, the formula for a circle who's Radius is 10, and it's center is in (0,0) is
X^2 + Y^2 = 100
now, when you enter coordinates, all you have to do is inser them in the formula.
if it's 100=100, then the point is ON the circle.
if x^2+y^2 < 100, the point is IN the circle
if x^2+y^2 > 100, the point is outside of the circle.
your problem isn't code, your problem is math, that's my opinion anyhow.
edit : here's how i'd do it, short as possible. if it's your homework and you're suppose to do it with bool, then all i can ask is WHY?
anyhow, as i said, once you know the formula, the rest is easy.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36
|
#include <iostream>
using namespace std;
int main()
{
double x,y,a,b;
bool run=true;
b=100;
while(run==true)
{
cout << "enter a point to check it's relative position to the circle\nenter a negative number to quit\n";
cout << "x value: "; cin >> x;
if(x<0)
{run=false;}
else
{
cout << "y value: "; cin >> y;
a = (x*x + y*y);
if(a<b){
cout << "inside circle\n";
}
if(a==b)
{
cout <<"on circle\n";
}
if(a>b) {
cout <<"outside of circle\n";
}
}
}
cout << "byebye";
cin.get();
return 0;
}
|
plus there's one thing i don't understand..
//Get a center point
cout << "Enter center of circle: ";
cin >> x1 >> y1;
//Get another point on the circle
cout<<"Enter a point on circle: ";
cin >> x2 >> y2;
cout << "Enter a point you want to find out, if it's inside the circle: ";
cin >> p_find_x >> p_find_y;
1)why get a center point? you were given the point(0,0)
2)why do you need two points on the circle to check if either one of them is on?
you were given the radius already, there's no need to calculate it.
make sure you answered what you were asked.
in any case, it's better to work with the full formula of the circle, which is
(x-a)^2 + (y-b)^2 = R^2
where (a,b) is the center location and (x,y) are the points on the circle.
needless to say that if you have2 out of the 3 variables(a,b)(x,y)(R) you can solve any problem related to distance from a point.
even making the program to give answers regarding any circle wouldn't use so many bools, is there a reason you focused on complex and somewhat confusing programing?
the last thing i'll write is program readability.
you must make your code as readable as possible, not only for others, but also for you. personally speaking it takes quiet a while to get information out of your code.
Keep posting if you still don't understand..