Help. Don't know how to figure out this For loop exponents question.

So I'm supposed to create a base and an exponent variable. Then by using a for loop I should be able to output the result. E.g 2 raised to the power of 2 should be for, or 2 to the power of 5 should be 32.

Here is what I got but it's not right.


1
2
3
4
5
6
7
8
9
10
int y = 1;

	for (int x = 1; x < 10; x++)
	{
		cout << x << " raised to the power " << y << endl;
		cout << x;
		y++;
		cout << endl;
	}
	


I'm only supposed to use for loops for this one, not functions.
It looks to me that you really don't understand what "power" means in this content.

2 to the power of 5 is equal to 2 * 2 * 2 * 2 * 2 which is equal to 32.

5 to the power of 2 is equal to 5 * 5 which is equal to 25
Topic archived. No new replies allowed.