Hi Everyone,
I am trying to compile a code and I keep getting error C2064: term does not evaluate to a function taking 1 arguments

here is my code(actually I got it from a book),can anyone help me what is wrong?

thanks
Negin

#include <iostream>
#include <math.h>
using namespace std;

class tridiagonal
{
private:
    int i,n;
    double *x,*a,*b,*c,*beta,*gamma,*r;

public:
    void input ();

    void solution ();

~tridiagonal ()
{
    delete [] x,a,b,c,beta,gamma,r;
}

};
void main()
{
    tridiagonal matrix;
    matrix.input ();
    matrix.solution ();

}
void tridiagonal :: input()
{
    cout<<"Enter number of equations:\n";
    cin >>n;

    a=new double[n-1];
    b=new double[n];
    c=new double [n-1];
    beta=new double[n];
    gamma=new double [n];
    r=new double [n];
    x=new double [n];
    for (i=0; i<n; i++)
    { cout<<"Enter b["<<i<<"]=" ;cin>> b[i];}

   for (i=0; i<(n-1); i++)
   { cout<<"Enter c["<<i<<"]=" ;cin>> c[i];}

   for (i=1; i<n; i++)

   { cout<<"Enter a["<<i<<"]=" ;cin>> a[i-1];}

   for (i=0; i<n; i++)

   { cout<<"Enter r["<<i<<"]=" ;cin>>r[i];}
}

void tridiagonal :: solution()
{
    for (i=0; i<n; i++)
    {
        if (i==0)
        {
            beta[0]=b[0];
            gamma [0] = r[0]/beta[0];
        }
        else
        {
            beta[i]=b[i]-a[i-1]*c[i-1]/beta[i-1];
            gamma[i]=(r[i]-a[i-1]*gamma[i-1])/beta[i];
        }
    }
    x(n-1)=gamma(n-1);

    for (i=(n-2); i>=0 ; i--)
    { x[i]=gamma[i]-c[i]*x[i+1]/beta[i]; }
    for (i=0; i<n ; i++)
    { cout<<"x["<<i<<"]="<<x[i]<<".\n";}

    }

Use code tags. Without them, all your indentation goes away, which makes your code very hard to read.

If your book really contained the line

delete [] x,a,b,c,beta,gamma,r;

then I suggest you stop using that book, because the author doesn't know C++ very well. Ditto for the overall design of the program.

That said, the first place I'd look for your error is in the line

x(n-1)=gamma(n-1);

which surely should be

x[n-1]=gamma[n-1];

if that's not the only problem, please repost the code using code tags, and please tell us which line or lines the compiler said was in error.

Thanks ,That seemed to be the problem.

Since I just started learning C++ by myself can you tellme how to force the program run line by line to find the problem?

Every time the compiler prints an error message during compilation, that message includes the number of the line with the problem.

>>Every time the compiler prints an error message during compilation, that message includes the number of the line with the problem.
And, in many IDEs, you can double-click the error message to be taken to the location of the error.

Thanks everyone

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.