I am supposed to write a function convert() that converts polar coordinates to rectangular coordinates; and then use it in a program that reads the polar coordinates for several points and calls convert(), which calculates and returns the rectangular coordinates for each point. It runs, but it's not calculating anything...The output is always coming out to 0.. What am I doing wrong???
#include "stdafx.h"
#include <iostream>
#include <cmath>
usingnamespace std;
double convert(double x,double y);
//{ int x,y;
// x = r cos 0;
//y = r sin 0;
//}
int main()
{
double r,o,x,y;
x=0.0;
y=0.0;
r=0.0;
o=0.0;
cout << "Enter polar coordinates. "<< endl;
cin >> r >> o;
cout << "The rectangular coordinates for the polar coordinates: " <<r<< " , "<< o<< " are " <<convert(x,y) <<endl;
return 0;
}
double convert(double x,double y)
{
double r =0.0, o = 0.0;
return x = r * cos (o);
y = r * sin (o);
}
Thank so much ne555! I got it to output a value other than zero, and I better understand how to use the function...This is the revised code...It still is only outputting one value, which I'm hoping is the ONLY bug left..
Ok, here is what I have worked out so far...I think the only issue with it now is that it's giving me a negative answer for the second value for some reason...What could be going on to cause that?
Here is an updated version of what I have...It works but the problem is that It's out putting the wrong information and I dont know why. I am using the formula given but, I haven't had any Trig so I don't know how to calculate cos and sin manually for desk checking..
The sin and cos functions in cmath probably assume that the angle given is in radians and not in degrees.
Convert your angle to radians before passing to sin and cos.