1. ## For Statement Question

Hello,
I am working on a program that asks the user to input an integer value. It then raises X to all the powers from 0 up to 5, using the user entered value.

For example, if the user entered 5 the output would be:

2 ^ 0 = 1
2 ^ 1 = 2
2 ^ 2 = 4
2 ^ 3 = 8
2 ^ 4 = 16
2 ^ 5 = 32

I have done this so far (Im pretty new to this stuff, so please dont completely blow me off):
Code:
```#include <iostream>

int main()
{
int i;

cin >> i;
for (i=i; i>=0; i*i)
{
cout << i;
cout << i << " ^ 0 = " << i ^ 0 << endl;
cout << i << " ^ 1 = " << i ^ 1 << endl;
cout << i << " ^ 2 = " << i ^ 2 << endl;
cout << i << " ^ 3 = " << i ^ 3 << endl;
cout << i << " ^ 4 = " << i ^ 4 << endl;
cout << i << " ^ 5 = " << i ^ 5 << endl;
}

cout << endl;
return 0;
}```
Here is a list of errors that I receive, I was wondering if anyone would be able to help me out here, what show I try changing?
I will continue working on it, but input would be appreciated greatly!

Errors:
Code:
```powersof2.cpp: In function `int main()':
powersof2.cpp:11: invalid operands `int' and `ostream & ()(ostream &)' to binary `operator <<'
powersof2.cpp:12: invalid operands `int' and `ostream & ()(ostream &)' to binary `operator <<'
powersof2.cpp:13: invalid operands `int' and `ostream & ()(ostream &)' to binary `operator <<'
powersof2.cpp:14: invalid operands `int' and `ostream & ()(ostream &)' to binary `operator <<'
powersof2.cpp:15: invalid operands `int' and `ostream & ()(ostream &)' to binary `operator <<'
powersof2.cpp:16: invalid operands `int' and `ostream & ()(ostream &)' to binary `operator <<'
powersof2.cpp:17: warning: statement with no effect```
I will try stuff, but It would be great if you could give me some feedback.
Thank you!

2. The ^ operator doesn't mean "raised to the power of", it means XOR.
You either need to add using namespace std; or use std::cout & std::endl
Also, I'm not sure what you're trying to do in that for loop?

3. If you want to do:
x^5 (power)

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

int main(){
float x;
cin >> x;
for(int i = 0; i < 5; i++){
cout << x << " ^ " << i << " = " << pow(x,(float)i) << endl;
}

}```
Is this how you wanted it?

This will output:

if user enters 3:
3 ^ 0 = 1
3 ^ 1 = 3
3 ^ 2 = 9
etc etc....

Don't use the direct ^ operator, that's XOR bitwise operator.
pow() is the function for power.

4. Originally Posted by execute
Code:
```#include <cmath>
#include <iostream>
using namespace std;

int main(){
float x;
cin >> x;
for(int i = 0; i < 5; i++){
cout << x << " ^ " << i << " = " << std::pow(x,(float)i) << endl;
}

}```
Corrections in red.

5. Originally Posted by Elysia
Corrections in red.
Since it has using namespace std; the second correction is optional.

6. Originally Posted by cpjust
Since it has using namespace std; the second correction is optional.
True, but I wanted to forward the message that the function is actually located inside the std namespace.

7. ## Thanks!

Wow, Thank you all so much for the excellent help.
I am very grateful that there are people out there to help me with this, rather than just give up on it.
I used what you all said, and it works.
Here is the final product:

Code:
```#include <iostream>
#include <cmath>
using namespace std;

int main()
{
int i;
float x;
i = 0;
cout << "Enter Number: " << endl;
cin >> x;
for (int i = 0; i < 6; i++)
{
cout << x << " ^ " << i << " = " << std::pow(x,(float)i) << endl;
}

return 0;
}```
Once again, thank you all so much!