How would I do this?

Using a for loop, write code that will compute the result of an int raised to the power of another int.
For example, your for loop should use two variables, one for the base and one for the exponent.
It should then calculate the base raised to the exponent.
2 raised to the power of 2 should output 4, 2 raised to 8 should output 256, etc.

You would do this by trying to write the code yourself, then posting the code you wrote here between code tags, so we can make an effort to try and help you find your errors..
Last edited on
Would this be the answer to this question?

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
{
	int y = 2;
	
	for (int x = 2; x < 10; x++)
	{
		cout << x << " raised to the power " << y << endl;
		cout << x*y;
		y++;
		cout << endl;
	}
	
	
	system("PAUSE");
	return 0;
}


This seems to compile and work fine, how about if the user would have to input the base variable and the exponent variable?
Last edited on
Topic archived. No new replies allowed.