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,
The ^ character represents a bitwise exclusive or, not the exponential function that you expect.
Since you're calculating this in a loop already you can easily generate the powers of 2 that you need in the equation, something simple (and close to your code) would be:
vector dist(5);
unsigned int j = 1;
for(unsigned int i = 2; i < 5; i++){
dist[i] = (4+3*j)/10.0;
j = j * 2;
}
In this particular instance, we initialize j to the first value of n-2 that you require, then proceed to multiply it by 2 to get the next power of 2 that you require.