Exponents and Square Roots

This is my question. I'm writing a program for an assignment that asks me "Determine the position of the dot M (x, y) relatively to the circle O (xo, yo, r)."

Below is what I have done so far, and I already know WHAT I have to do, but I wanted to know HOW to do it. How would I do the following, for example:

m=x^2 + y^2
and then the square root of m.

Thank you!

#include <iostream>
#include <math.h>
using namespace std;

int main(){
int x, y, m, a, b, r, i=2;
cout<<"Enter the coordinates (Dot) for x and y, respectively."<<endl;
cin>>x;
cin>>y;
cout<<"Enter the coordinates (Circle) for a and b, respectively."<<endl;
cin>>a;
cin>>b;

while((x>0)&&(y>0)&&(a>0)&&(b>0))
{

Firstly, you may need to clarify things a bit.

The distance of M from the CENTRE of the circle is
d = sqrt( (x-x0)^2 + (y-y0)^2 ).

The distance of M from the actual circle BOUNDARY is
abs( d - r ).

And 'position relative to ..." may mean more than just distance from.


If you want a small power, say the square, then just use a multiply; i.e. code
"x squared" as x * x. Incidentally, '^' does NOT yield a power in C++.

If you want a square root use sqrt(), and include the header <cmath>.

I can't see any good use for your while statement.




Topic archived. No new replies allowed.