### Trouble with "pow" function

I know posting a new thread for the same question is frowned upon around here, but I stopped getting replies in the other one, so..

Here is the Question:

Write a program to compute, and later output to the screen, the sum of the series Sn, where Sn is the sum, from i = 1 to n, of ( n + n2 ) / 3. The value n, is entered, via the keyboard, by the user.

Here is what I've got now:

 ``12345678910111213141516171819202122232425`` `````` #include #include using namespace std; int main () { int i = 1; int n, Sn, sSum = 1; cout << "Please enter a value for n: "; cin >> n; for( i; i <= n; i++) { Sn = ( n + pow(n,2) ) / 3; sSum += Sn; } cout << sSum; system("PAUSE"); return 0; } ``````

I've included <math.h>, but that has not solved the problem of being able to use the pow function.

I'm still having the same issue with this:

`Sn = ( n + pow(n,2)) / 3`

The "pow" has a squiggly red line under it, and I get an error message:

 IntelliSense: more than one instance of overloaded function "pow" matches the argument list

I don't understand.

Last edited on
This doesn't cause the same IntelliSense error in VS Express 2013. Could be that your version can't determine what type variable 2 represents, since it's the only element of your argument list that isn't already declared. Try using 2.0 instead, see what happens.

1. Power and division math using int variables will give you some oddball results, since all results will be truncated to integers. i.e. 14/3 = 4.66666. . . in double math, but only 4 in integer form.

2. I think you mean to use i as your variable in line 16, right? If not, then you merely have to multiply (n + pow(n,2)) by n to get the result, and I don't think that's what the question is asking for.

3. Why do you initialize sSum to 1?
Last edited on
Don't you mean the sum from i= 1 to n of (i+i2)/3? The sum for i=1 to n of (n+n2)/3 is just n(n+n2)/3

To avoid overflow and rounding errors, make i and Sn doubles instead of ints.
Topic archived. No new replies allowed.