I am trying to make something like this:
2^1 + 2^2 + 2^3 + 2^4 + ... + 2^n
This is my code:
#include <iostream>
int main(){
int n, p=0;
std::cout<<"N: ";
std::cin>>n;
for(int i=1; i<=n; i++){
p = p+(2^i);
}
std::cout<<p;
return 0;
}
The result is always incorrect. If I input 4, the result is 10. If I input 5, the result is 17
I think the problem is in p = p+(2^i);
but I am not sure.