01235

01235
Last edited on
Post what you have done so far. We don't care about doing YOUR homework (at least I don't). We may care, however, to help out in a SPECIFIC problem that you are having.
can we have a nice conversations over this forum at least pick a more appropriate words not that to harsh..
haha, what hurt your feelings? That I don't care? Is that harsh? I mean... lol, I just don't see it!
if you dont care then why should you say it dont reply if you dont care ..
Please read more carefully: "I don't care about doing YOUR homework, but I may care help out with something more specific".

Clear enough? That I don't care about something doesn't mean that I don't care about anything. Big difference, I would say.
Last edited on
11111
Last edited on
Well, the thing is, Zakuro, that I am not sure about your skill. I mean, do you even know how to create a Hello World program? Do you know how to read keyboard input? Do you understand what a variable is? Are you aware of the data types that exist in C++? Do you see where I am going? I don't know what it is that you do not understand. This is why I encourage you to post whatever you CAN do, so it is clear to everybody reading what you need help with.
WebJose has a very good point, many good points. You may even find that if you attempt it you don't even need help. See how this works? People wishing to do programming need to work out that to learn how to solve problems, and to learn programming that you are the only person who can teach yourself.
Teachers mostly only guide as to how to find resources and give a curriculum but it's up to us to learn. Asking for code on forums doesn't teach you anything and takes up our time. Post what you have if you have problems and we will endeavour to help, otherwise you may as well mark as solved :)
143
Last edited on
Code tags.
Well the problem is that what you're doing is basically checking if the point is within a square.
To check if its within a circle you have to use the formula given to you ((sqrt(x[2]-x[1])^2 + (y[2]-y[1])^2)) and check if the distance is less than the radius.
Don't you have to calculate the radius from x1,y1,x2,y2 first?, at least you didn't define radius.
000
Last edited on
closed account (jLNv0pDG)
to deal with one or two of the eerrors you already have. On lines 33 & 35 you use the variables p_find_x, p_find_y and radius but you haven't initialised or defined them anywhere.

1
2
3
	cin >> p_find_x >> p_find_y;

if (insideCircle(radius, p_x, p_y, p_find_x, p_find_y) == true)



to deal with one or two of the eerrors you already have. On lines 33 & 35 you use the variables p_find_x, p_find_y and radius but you haven't initialised or defined them anywhere.

1
2
3
 	cin >> p_find_x >> p_find_y;

if (insideCircle(radius, p_x, p_y, p_find_x, p_find_y) == true)




He declares it but it's in an inline function after the cin command.

bool insideCircle (double radius, double p_x, double p_y, double p_find_x, double p_find_y)

AND what exactly IS the result your getting??
Last edited on
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..
Last edited on
How do I use setprecision with this program.

my outputs are supposed to look like this:

1. Enter a point with two coordinates: 4 5
Point (4.0, 5.0) is in the circle

and

2. Enter a point with two coordinates: 9 9
Point (9.0, 9.0) is not in the circle.



the end of my program is supposed to look like this:

cout.setf(ios::fixed);
cout.precision(1);

cout << "x is " << x << " and y is " << y << endl; // Returns the values of x and y.

return 0;
}

Here is my program:


#include <iostream>
#include <iomanip>
using namespace std;

int main()
{
float x,y,a,b;
bool run=true;
b=100;
while(run==true)
{
cout << "Enter a point with two coordinates:"<<endl;
cout << "x is " << x << " and y is " << y << endl;
cin >> x >> y;

if(x<0)
{
run=false;
}
else
{
a = (x*x + y*y);

if(a<b)
{
cout << setiosflags(ios::fixed) << setprecision(1);
cout << "Point"<< x << y << " is inside circle"<<endl;
}

if(a>b)
{
cout << setiosflags(ios::fixed) << setprecision(1);
cout <<"Point"<< x << y << " is outside of circle"<<endl;
}
}
}
cout.setf(ios::fixed);
cout.precision(1);

cout << "x is " << x << " and y is " << y << endl; // Returns the values of x and y.

return 0;
}




could someone add the set precision please. I tried but I have build errors.
Last edited on
cout << "Enter a point with two coordinates:"<<endl;
cout << "x is " << x << " and y is " << y << endl;
cin >> x >> y;

you're printing the value of X and the value of Y,
but you only ask for their values in the next line. so, what's up with that?


here's a basic tutorial concering precision:
http://www.cplusplus.com/reference/iostream/ios_base/precision/

this is the precision explanation.
Give it a shot, write a diffrent program using only the precision parameters, see how it works, then try to implement it on a bigger program.
If you can't get it to work on a program that's dedicated to that function, then post again, and we'll see how we can help.
Topic archived. No new replies allowed.