Jump to content

Home

c++ help


Tinny

Recommended Posts

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

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

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

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 :confused:

#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

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...