Become a MacRumors Supporter for $50/year with no ads, ability to filter front page stories, and private forums.
um still not that great. i dont understandwhat i should initialize x and y to. i looked in my book and the only example on the reference stuff is with the quadratic equation and i cant follow it what so ever. so its not looking too great. im really not sure what else im supposed to change here! i feel like im close though

Post your code and state which 'x' and 'y' you're referring to.

I getting pissed at this forums posting interface. I keep trying to make a separate post form this one but since I'm the last poster it keeps appending.

It's both irritating and confusing!
 
now that i changed my initialization of variables (see my last edit) it isnt telling me it has to be initialized anymore.
 
Thanks for that!

Code:
int main ()
{
	double x;
	double y; 
	double r; 
	double angle;

because in the example i have it doesnt show the & in the initialization. when i do this the program runs, but its still wrong. ie: if i input 3, it spits 3 back out. so i know im not done, but was this a good move? is the & not supposed to be in the main body?

That part seems correct but post the full source.
 
Code:
#include <iostream>
using namespace std; 
#include <cmath>

double polar (double &, double &, double, double);

int main ()
{
	double x;
	double y; 
	double r; 
	double angle;
	
	cout << "Enter two numbers for polar coordinates: ";
	cin >> r, angle; 

	polar (x, y, r, angle);

	cout << "The corresponding rectangular coordinates are (" << x << ", " << y << ")" << endl;
	
	return 0; 
}

double polar (double & x, double & y, double r, double angle) 
{
	x = r * cos (angle);
	y = r * sin (angle);
	
	return x;
	return y;
}

i feel like this should work!!! i dont know what im missing
 
I see! THe values are being return thru their references passed as parameter to the routine. There is no longer a need to explicitly 'return' anything!
 
I see! THe values are being return thru their references passed as parameter to the routine. There is no longer a need to explicitly 'return' anything!

so i can remove the return in the function definition?

and does this main change the function prototype to void? since there will be no return?
 
It's just as easy to try as ask it!

i removed return and changed to void, but when i input test case (3.5, 20) it still returns, 3.5 and 0 rather than the proper numbers :/

and i get this warning: polar.cpp:15:12: warning: expression result unused [-Wunused-value]
cin >> r, angle;
 
Code:
#include <iostream>
using namespace std; 
#include <cmath>

void polar (double &, double &, double, double);

int main ()
{
	double x;
	double y; 
	double r; 
	double angle;
	
	cout << "Enter two numbers for polar coordinates: ";
	cin >> r, angle; 

	polar (x, y, r, angle);

	cout << "The corresponding rectangular coordinates are (" << x << ", " << y << ")" << endl;
	
	return 0; 
}

void polar (double & x, double & y, double r, double angle) 
{
	x = r * cos(angle);
	y = r * sin(angle);
	
}

thanks for your patience :D:D:D
 
The prototypes for cos and sin are already in your
Code:
#include <cmath>

The point I was trying to make is that to test r=3.5 angle=20 degrees you need to input (20*(pi/180)) radians into sin and cos.

Also, check and see if your input values are being set properly. Are you operating on good input?

B
 
Last edited:
still confused :p lol so are you saying i dont need to change my code? just my input? how do i check if im operating on good input, i dont understand what that means

How might you tell if the values you are operating on in your function are what you think provided as input? (Hint: use the debugger, or some kind of output?)

B
 
How might you tell if the values you are operating on in your function are what you think provided as input? (Hint: use the debugger, or some kind of output?)

B

i really have no clue what youre talking about. sorry :confused::confused:
 
Maybe something similar to your

Code:
cout << "The corresponding rectangular coordinates are (" << x << ", " << y << ")" << endl;

for r and angle instead of x and y could be useful somewhere?


----------

SHe working from the Terminal and a text editor!

That's why I suggested the alternative. However gdb still works from the command line if you want it to. ;)

B
 
Maybe something similar to your

Code:
cout << "The corresponding rectangular coordinates are (" << x << ", " << y << ")" << endl;

for r and angle instead of x and y could be useful somewhere?

B

i have to follow the output that my professor gives us though.. so i cant add anything else in. and im still not sure i comprehend what youre talking about
 
Direct hint: Something is wrong with your cin.

You can add other debug output to make sure it is good and then take them out.

B
 
Direct hint: Something is wrong with your cin.

You can add other debug output to make sure it is good and then take them out.

B

sorry forbeing so dumb, what could be wrong with my cin? this is the program from hell.

edit:

is this why im getting this warning?
polar.cpp:15:12: warning: expression result unused [-Wunused-value]
cin >> r, angle;
 
Register on MacRumors! This sidebar will go away, and you'll see fewer ads.