Tinny Posted May 10, 2004 Share Posted May 10, 2004 hey guys, i tried to write a program that would convert cartesian coordinates to spherical. but my compiler is giving me an error, what did i do wrong? here's the code: #include <iostream.h> #include <stdlib.h> #include <math.h> int main() { float x, y , z, rsq, yox, rho, theta, thetad, zor, phi, phid; cout << "Input the cartesian coordinates." << endl; cout << "x:"; cin >> x; cout << "\n"; cout << "y;"; cin >> y; cout << "\n"; cout << "z;"; cin >> z; rsq = x*x + y*y + z*z; yox = y / x; rho = sqrt (rsq); theta = atan (yox); thetad = theta * 180 / 3.1415926535898; zor = z / rho; phi = acos (zor); phid = phi * 180 / 3.1415926535898; cout << "The spherical coordinates are (" rho "," theta ", and" phi")"; cout << "\nWhere Rho is:\t" rho; cout << "\nTheta is:\t" theta "radians or" thetad "degrees"; cout << "\n and Phi:\t" phi "radians or" phid "degrees."; system("PAUSE"); return 0; } Link to comment Share on other sites More sharing options...
matt-- Posted May 10, 2004 Share Posted May 10, 2004 Changes are un-bolded. Originally posted by Tinny hey guys, i tried to write a program that would convert cartesian coordinates to spherical. but my compiler is giving me an error, what did i do wrong? here's the code: #include <iostream.h> #include <stdlib.h> #include <math.h> int main() { float x, y , z, rsq, yox, rho, theta, thetad, zor, phi, phid; cout << "Input the cartesian coordinates." << endl; cout << "x:"; cin >> x; cout << "\n"; cout << "y;"; cin >> y; cout << "\n"; cout << "z;"; cin >> z; rsq = x*x + y*y + z*z; yox = y / x; rho = sqrt (rsq); theta = atan (yox); thetad = theta * 180 / 3.1415926535898; zor = z / rho; phi = acos (zor); phid = phi * 180 / 3.1415926535898; cout << "The spherical coordinates are (" << rho << "," << theta << ", and" << phi << ")"; cout << "\nWhere Rho is:\t" << rho; cout << "\nTheta is:\t" << theta << "radians or" << thetad << "degrees"; cout << "\n and Phi:\t" << phi << "radians or" << phid << "degrees."; system("PAUSE"); return 0; } That should do it. Link to comment Share on other sites More sharing options...
GonkH8er Posted May 10, 2004 Share Posted May 10, 2004 Damn you... beat me to it Link to comment Share on other sites More sharing options...
Tinny Posted May 11, 2004 Author Share Posted May 11, 2004 thankyou guys for all the help Link to comment Share on other sites More sharing options...
Mike Windu Posted May 12, 2004 Share Posted May 12, 2004 I believe they're being sarcastic... >_> <_< Link to comment Share on other sites More sharing options...
IG-64 Posted May 12, 2004 Share Posted May 12, 2004 Originally posted by Mike Windu I believe they're being sarcastic... >_> <_< i'm sure its not all that hard to do once you sit your butt down and study it. It just takes time, will, and patience. Link to comment Share on other sites More sharing options...
GonkH8er Posted May 12, 2004 Share Posted May 12, 2004 Originally posted by Mike Windu I believe they're being sarcastic... >_> <_< No sarcasm at all. He actually beat me to it and i actually would have done it Link to comment Share on other sites More sharing options...
acdcfanbill Posted May 15, 2004 Share Posted May 15, 2004 but its still all bold :s Link to comment Share on other sites More sharing options...
coupes. Posted May 15, 2004 Share Posted May 15, 2004 Originally posted by acdcfanbill but its still all bold :s I though the same thing... but here are the differences, if anyone is sill interested #include <iostream.h> #include <stdlib.h> #include <math.h> int main() { float x, y , z, rsq, yox, rho, theta, thetad, zor, phi, phid; cout << "Input the cartesian coordinates." << endl; cout << "x:"; cin >> x; cout << "\n"; cout << "y;"; cin >> y; cout << "\n"; cout << "z;"; cin >> z; rsq = x*x + y*y + z*z; yox = y / x; rho = sqrt (rsq); theta = atan (yox); thetad = theta * 180 / 3.1415926535898; zor = z / rho; phi = acos (zor); phid = phi * 180 / 3.1415926535898; cout << "The spherical coordinates are (" [color=red]<<[/color] rho [color=red]<<[/color] "," [color=red]<<[/color] theta [color=red]<<[/color] ", and" [color=red]<<[/color] phi [color=red]<<[/color] ")"; cout << "\nWhere Rho is:\t" [color=red]<<[/color] rho; cout << "\nTheta is:\t" [color=red]<<[/color] theta [color=red]<<[/color] "radians or" [color=red]<<[/color] thetad [color=red]<<[/color] "degrees"; cout << "\n and Phi:\t" [color=red]<<[/color] phi [color=red]<<[/color] "radians or" [color=red]<<[/color] phid [color=red]<<[/color] "degrees."; system("PAUSE"); return 0; } Link to comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.