Base and exponents

how to write this line?
e=y^2+y^4+y^8.
I tried this but it doesnt do the job

1
2
3
4
5
6
7
8
int main(){
  int y,exponent=2;
for (i = 1; i <= n; i++){
		cout << y << "^" << exp2 << " = " << pow(y, exp2) << endl;
		exp2++;

	}
}
how to write this line?

Depends what you mean by "write".

Your code seem a mixture of two different concepts:

1. displaying some text
- in which case cout << i << "^2" << etc. would be suitable

2. calculating the result of an expression
- in which case cout << pow(i, 2) + etc. would make more sense.
Topic archived. No new replies allowed.