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.
#include <iostream>
#include <math.h>
usingnamespace 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
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.
Three additional comments:
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.