Power Function Problems

I need to get a function that produces
1
2
3
4
5
6
7
8
9
0     1
1     2
2     4
3     8
4     16
5     32
6     64
7     128
8     256


This is what I have so far.

1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>
using namespace std;

int main()
{
	int base=2;
	int answer = 1;
	for(int i=0; i<=8; i++)
	{
			answer=answer*base;
			cout<<i<<"      "<<answer<<endl;
	}
}


The problem is that it is off by 1 power, and when I try to correct it I end up with all zeros as my answers. Please Help.
Last edited on
Swap lines 10 and 11.
What a boss. Thanks!
Topic archived. No new replies allowed.