Rectangular To Polar Coordinate Conversion

Hi guys, a little problem here. When a try to compile this program, I end up with the error:
"prog.cpp: In function ‘void displayresult(double, double)’:
prog.cpp:92:9: error: cannot resolve overloaded function ‘distance’ based on conversion to type ‘double’
radius = distance;"
^
Can anyone help? Thanks!
P.S.
I'm not exactly sure how to find theta and tangent, or even what they are, so if there's something wrong with my mathematical formulas, fixing them would be a great help too.

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
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
#include <iostream>
#include <cstdlib>
#include <cmath>
using namespace std;

void getdata(double& x, double& y);
void polar(double x, double y, double& r, double& theta);
void displayresult(double radius, double angle);

int main()
{
    double x, y, distance, angle;
    char repeat;
    
    do
    {
    	system("cls");
    	
    	cout << "Rectangular to Polar Coordinate Conversion" << endl;
    	cout << "------------------------------------------" << endl << endl;
    	
    	getdata(x,y);
    	
    	if (x == 0)
    	{
    		;
    	}
    	else
    	{
    		polar(x, y, distance, angle);
    		
    		cout << endl << endl;
    		
    		displayresult(distance, angle);	
    	}

    	cout << endl;
    	cout << "Run the program again? [y/n]: ";
    	cin >> repeat;
    	cout << endl << endl;
    } while (repeat == 'y' || repeat == 'Y');

    return 0;
}

void getdata(double& x, double& y)
{
	cout << "Enter the x coordinate: ";
	cin >> x;
	cout << endl;
	cout << "Enter the y coordinate: ";
	cin >> y;
	cout << endl << endl;
	
	if (x == 0)
		cout << "Error: value of x cannot be 0.";
	
	return;
}

void polar(double x, double y, double& r, double& theta)
{
	int a = x;
	int b = y;
	int c = r;
	
	if (y == 0)
	{
		r = x;
	}
	else
	{
		c = sqrt((a^2) + (b^2));
		r = c;
	}
	
	theta = ((tan(-1)) * (a/b));
	
	return;
}

void displayresult(double radius, double angle)
{
	radius = distance;
	angle = angle;
	
	cout << "Polar coordinates: " << endl << endl;
	cout << "Distance from origin = " << radius << endl;
	cout << "Angle (in degrees) from x-axis = " << angle << endl;
}
Line 73: ^ is not an operator for power. You could write sqrt(a*a+b*b)


Line 84: you assign to 'radius' (a double parameter of the function) the value of 'distance'. The only name 'distance' known at this point in the function is probably 'std::distance' -- a function make visible on global scope due to "using namespace std;".

Line 85: you assign the value of 'angle' to 'angle', which make no sense.
Oh lol, sorry. But how do you suggest I assign the value of r to radius? Whenever I try "radius = r", I end up with "r was not declared in this scope."
Never mind, I figured it out by myself. Thanks keskiverto! Honestly, I don't remember what made me think that ^ was an operator for power. XD
Topic archived. No new replies allowed.