Thread: Problem with Calling Filter

  1. #1
    Registered User
    Join Date
    Apr 2006
    Posts
    2

    Problem with Calling Filter

    My problem is that I cannot get the digfilter to call from main correctly. I know that it needs the pointers, but I don't know if the ones I used are correct. I also am not sure if my cout statement in main for printing the final data to the screen is correct. Any input is greatly appreciated. I'm trying to study for a test and I need to be able to make these types of programs work correctly. The code follows. Thanks guys/gals.

    Code:
    #include <cstdlib>
    #include <iostream>
    #include <fstream>
    
    using namespace std;
    
    void getXvalues(int *numpoints, double x[])
    {
        cout << "Please enter the number of points: ";
        cin >> *numpoints;
        for (int i = 0; i < *numpoints; i++)
        {
            cout << "Please Enter a Point: ";
            cin >> x[i];
        }
    }
    
    
    void digfilter(int numpoints, double *x, double *y, double *z)
    {
        y[0] = z[0] = x[0];    
        for (int i = 1; i < numpoints; i++)
        {
            y[i] = (x[i]+ x[i])/2 > 1;
            z[i] = (.5*(x[i] + z[i-1]));
        }
    }
    
    int main(int argc, char *argv[])
    {
        double input[50];
        int numpts;
        getXvalues(&numpts, input);
        double *outputx = new double[numpts];
        double *outputy = new double[numpts];
        double *outputz = new double[numpts];
        digfilter(numpts, outputx, outputy, outputz);
        ofstream outpt("Output.txt");
        for (int i = 0; i < numpts; i++)
        {
            outpt << outputx[i] << outputy[i] << outputz[i]<< endl;
            cout << " X = " << outputx[i] << " Y = " << outputy[i] << " Z = " << outputz[i];
        }
        outpt.close();
        delete outputx, outputy, outputz;
        system("PAUSE");
        return EXIT_SUCCESS;
    }

  2. #2
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    >> (x[i]+ x[i])/2 > 1
    What are you trying to do with the greater than sign there? Isn't (x[i]+ x[i])/2 always x[i]?

    >> outpt << outputx[i] << outputy[i] << outputz[i]<< endl;
    This will run the numbers together in the output file. Is that what you want?

    >> delete outputx, outputy, outputz;
    That's not the proper syntax. You have to delete each array separately, and you have to use delete [] instead of delete (For future reference, you should use vectors in C++ instead of dynamic C-style arrays for this purpose).

    It looks like you are calling digfilter correctly, and your output to cout looks fine (although perhaps you could use a newline in there somewhere).

  3. #3
    Registered User
    Join Date
    Apr 2006
    Posts
    2
    The > 1 filter was what was requested by my professor, so that's why its like that. The numbers probably shouldn't run together now that I look at it. and I don't know alot about proper syntax of vectors vs dynamic arrays, its just how he taught us to do it. But thank you for the tips.

  4. #4
    Registered User
    Join Date
    Jan 2005
    Posts
    7,366
    >> I don't know alot about proper syntax of vectors vs dynamic arrays, its just how he taught us to do it.
    Don't worry about vectors now, that's just a heads up for if you plan to continue your programming in C++ in the future. However, you should worry about delete outputx, outputy, outputz; which is the wrong way to delete an array. If your professor taught you to do it that way then it was a serious mistake.

    >> The > 1 filter was what was requested by my professor, so that's why its like that.
    Are you sure you implemented what your professor asked for correctly? It doesn't make sense to me. What exactly do you (or your professor) expect that line of code to do?

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Problem calling the function
    By HAssan in forum C Programming
    Replies: 6
    Last Post: 12-30-2005, 04:36 PM
  2. DLL Function / Load Library Problem
    By cboard_member in forum Windows Programming
    Replies: 5
    Last Post: 12-10-2005, 10:11 AM
  3. Replies: 5
    Last Post: 11-07-2005, 11:34 PM
  4. searching problem
    By DaMenge in forum C Programming
    Replies: 9
    Last Post: 09-12-2005, 01:04 AM
  5. half ADT (nested struct) problem...
    By CyC|OpS in forum C Programming
    Replies: 1
    Last Post: 10-26-2002, 08:37 AM