need help about math c++

hello, i am currently new in programming. So I made a program to basically calculate 2^n (n user input)

#include <iostream>
#include <math.h>
using namespace std;

int main(){
int i, n;
cout << "Enter a number : ";
cin >> n;

for(i=1; i<=n; i++){
cout <<pow(2,i) << " " << endl;
}
}

for example, if I input 4, it will shows 2 4 8 16, my questions is
what syntax do I need to add in order to calculate all those numbers?
(2 + 4 + 8 + 16 = ? )

thank you
Maybe
sum += pow(2,i);
Topic archived. No new replies allowed.