What's the error?

 ``1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253`` ``````#include #include void main() { clrscr(); int choice, x, N, u, temp; float sum; cout<<"1. x+x^2+x^3+x^4....N times"<>choice; switch(choice) { case 1: { cout<<"Enter N: "; cin>>N; cout<<"Enter x: "; cin>>x; for(int i=0; i>N; cout<<"Enter u: "; cin>>u; for(int i=2; i<(N+2); i++) { sum+=u; u*=(u/i); } cout<<"The sum of the required series is:"<>N; for(int i=2, k=2; i<(N+2); i++, k++) { temp=i; sum+=temp; temp*=k; } cout<<"The sum of the series is:"<

The output comes out to be:
 ``` 1. x+x^2+x^3+x^4....N time 2. u+(u^2/2!)+(u^3/3!).....N times 3. 2+(2+4)+(2+4+6)...N times Enter your choice:1 Enter N: 3 Enter x: 2 The sum of the series is: 22```
(2+4+8 not equal to 22)
But it should be like:
 ```1. x+x^2+x^3+x^4....N time 2. u+(u^2/2!)+(u^3/3!).....N times 3. 2+(2+4)+(2+4+6)...N times Enter your choice:1 Enter N: 3 Enter x: 2 The sum of the series is: 14```
(2+4+8=14)
Where are you initialising sum? I don't see you doing that anywhere.

Did your compiler not warn you about using it before you initialise it?
Ok i did that..and no the compiler didnt warn me..
But still the output comes as above..22 not 14
The problem is in line 18. You multiply the current value of x by itself instead of the original value of x. So you are adding 2 + (2*2) + (4*4). You need to copy the original value of x to, say Y, and then change line 18 to
`y *= x;`
Oh yes..thanks :)
Topic archived. No new replies allowed.