So I am trying to make a basic C++ program that calculates the mean, eccentric, and true anomalies as well as the radial distance and velocity of a planet. This is one of my first programs I have worked on, so I know it's not as concise as it could be. I'm just having a hard time getting it to run. I know some of the values might need to be converted to make the units match up, and I can do that later. I just want to know what is causing it not to run. Also in main, I have if statements for every planet; I didn't include the rest because it would just take up too much space.
Ultimately, the goal of the program is to print a table of times, the anomalies, r, and v given the planet name. If you need any clarification, please let me know. Thank you
Thanks in advance
const float G = 6.673E-11;
const float solar_m = 1.989E30;
const float mu = G*solar_m;
class Planet
{
double a, ec, T;
public:
void SetValues(float, float, float);
float Calculations();
};
void Planet::SetValues(float m_a, float m_ec, float m_T)
{
m_a = a;
m_ec = ec;
m_T = T;
}
float Planet::Calculations()
{
//Set up values
a = a*1.496E11; //AU to m
T = T*365; //Period converted to days
float delta = 0.001;
float M;
float E;
float E1;
float E2, f_E2;
float E3, f_E3;
float f,r,v;
for(int t; t<T; t++)
{
M= sqrt(mu/(a*a*a))*t;
E1= M;
E2 = (M-E1+ec*sin(E1))/(ec*cos(E1)-1);
f_E2 = M-E2+ec*sin(E2);
E3 = (M-E2+ec*sin(E2))/(ec*cos(E2)-1);
f_E2 = M-E3+ec*sin(E3);
if (f_E2<delta)
E=E2;
else if (f_E3<delta)
E=E3;
else
cout<<"not enough iterations";
f = 2*atan(sqrt((1+ec)/(1-ec))*tan(E/2));
r = (a*(1-ec*ec))/(1+ec*cos(f));
v = sqrt(mu*(2/r -1/a));
cout<< t<<" "<<M<<" "<<E<<" "<<f<<" "<<r<<" "<<v;
}
};
int main()
{
int i;
float t;
string pName;
cout<<"What planet do you want to simulate?";
cin>>pName;
if (pName.compare("mercury") || pName.compare("Mercury"))
{
Planet me;
me.SetValues(.387, .2056, .24);
me.Calculations();
};