You don't re-initialise each of res1 and res3 before you try to compute them. Also, res2 would have to be set correctly before use on line 25.
Your code will "work" (in the sense that it will produce a vaguely credible answer) if:
(1) You put
res1 = 1;
between lines 20 and 21.
(2) You put
1 2
|
res2 = 2 *n + 1;
res3 = 1;
|
between lines 24 and 25. (Note that you will be moving the setting of res2 forward.)
As @Keskiverto pointed out, your indentation is all over the place.
There are better and more efficient ways of summing power series like this. Note that the terms are
x
-x
3/3 = (previous term) * (-x
2) * 1 / 3
x
5/5 = (previous term) * (-x
2) * 3 / 5
-x
7/7 = (previous term) * (-x
2) * 5 / 7
Spot a pattern?
You should compute each new term as a simple multiple of the previous one, not try to work out things like x
3000 or, worse, (-1)
3000, using for-loops.
Incidentally, 3000 is a magic number. This series is, strictly, a sum of an infinite number of terms that you must truncate. Note that, as it has terms of monotonically-decaying magnitude and alternating signs, the truncation error will always be less in absolute magnitude than the last computed term.