Why am I not getting correct result when I calculate exponent with ^ in C++?
- by xbonez
I am using Bode's formuala to calculate distance of nth planet from sun
dist = (4 + 3*(2^(n-2)))/10
If I calculate the distance this way, I get the right values:
dist[2] = ((4 + 3*1)/10.0) ;
dist[3] = ((4 + 3*2)/10.0) ;
dist[4] = ((4 + 3*4)/10.0) ;
But doing it this way, gives me incorrect values:
vector <double> dist(5);
for (unsigned int i = 2; i < 5; i++)
{
dist[i] = ((4 + 3*(2^(3-2)))/10.0) ;
}
Why so?