#include <iostream>
#include <cmath>
using namespace std;

int main ()
    double n = 1;
    double sum = 0 ;
    double previous = 0;
    double y;
    while(fabs(double (sum - previous)) > 0.001)
        y = -1 (exp(double (n))) / n;                   **<<<Error is here<<<<**
        sum += y;
        previous = sum - y;
        if (fabs(sum-previous) < 0.001)
            cout << " The sum is =" << sum << "\n";

    return 0;


The error is on line 13 im getting a 1>.\sum.cpp(13) : error C2064: term does not evaluate to a function taking 1 arguments i have no clue why is giving me that error plaease help me out with this one.....thanks in advance...

It thinks -1 is the name of a function. You can't code an algorithm like that. Do you mean -1* (exp(double (n))) / n; ?? (multiplication)

Is there supposed to be something between that -1 and (exp(double (n)))?

While I'm here, why is it (double(n)) and not just n? Given that n is already a double. Likewise line 11.

Edited 3 Years Ago by Moschops

well on that line what i want to say is (negative one raised to the n power)= numerator...then numerator divided by the n number...how can i go about this in a logical way for c++?

ok perfect....thanks alot...the program is running now but is not displaying anything.... the point of the program is to perform the sum of y = (pow(-1.0, n))/n....until absolute value of (sum minus the previous sum) is less than 0.001.... the program immediately stops and displays the sum at that point...any suggestions?

while(fabs(double (sum - previous)) > 0.001)

sum and previous both begin as zero, so sum - previous is zero, so the loop never executes.

Edited 3 Years Ago by Moschops

This article has been dead for over six months. Start a new discussion instead.