Help~! I don't know what's wrong with this program.

Discussion in 'C++' started by titan0111@hotmail.com, Dec 13, 2004.

  1. Guest

    #include<iostream>
    #include<iomanip>
    #include<cstring>
    #include<fstream>
    using namespace std;

    class snowfall
    {
    private:
    int ft;

    float in;
    float totalsfin;

    char date[6];

    static int validcount;
    static int invalidcount;

    public:
    void readdata(ifstream& infile)
    {
    infile>> ft >> in >> date;
    }

    void writedata(ofstream& outfile)
    {
    outfile<< ft << in << date;
    }

    void updatevalidcount()
    {
    validcount++;
    }

    void updateinvalidcount()
    {
    invalidcount++;
    }

    void calctotalsf()
    {
    totalsfin += float(ft)*12 + in;
    }

    int getft()
    {return ft;}

    float getin()
    {return in;}

    char* getdate()
    {return date;}

    int getvalidcount()
    {return validcount;}

    int getinvalidcount()
    {return invalidcount;}

    int operator == (char[]);
    char datavalid();
    void writetotalsf(ofstream& outfile);
    };

    int snowfall::eek:perator == (char sf[])
    {
    return (strcmp(date, sf) == 0) ? 1 : 0;
    }
    char snowfall::datavalid()
    {
    char valid;

    if ((ft >= 0) && (in >= 0.0f))
    valid = 'T';
    else
    valid = 'F';
    return valid;
    }
    void snowfall::writetotalsf(ofstream& outfile)
    {
    int totalsfft = 0;

    if (totalsfin >= 12.0f)
    while (totalsfin <= 11.0f)
    {
    totalsfft++;
    totalsfin -= 12.0f;
    }

    outfile<< "/nThe total amount of snowfalls: " << totalsfft
    << " feet " << totalsfin << " inches.\n";
    }


    void main()
    {
    snowfall sf[10];
    snowfall validsf[10];
    snowfall invalidsf[10];

    void writetitle(ofstream&);
    void writeheadings(ofstream&);
    void sortsf(snowfall);
    void writevalidsf(snowfall, ofstream&);
    void writeinvalidsf(snowfall, ofstream&);


    ifstream infile;
    ofstream outfile;

    infile.open("c:\\downloads\\input.txt");
    outfile.open("c:\\downloads\\output.txt");

    if (infile && outfile)
    {
    int j = 0;
    int k = 0;

    writetitle(outfile);

    for (int i = 0; i <= 10; i++)
    {
    sf.readdata(infile);

    if (sf.getdate() == "00/00")
    i = 10;
    else
    {
    if (sf.datavalid() == 'T')
    {
    validsf[j] = sf;
    sf.updatevalidcount();
    sf.calctotalsf();
    j++;
    }
    else
    {
    invalidsf[k] = sf;
    sf.updateinvalidcount();
    k++;
    }
    }
    }

    sortsf();
    writeheadings(outfile);
    writevalidsf(outfile);
    writeinvalidsf(outfile);
    validsf.writetotalsf(outfile);
    }
    else
    {
    if (!infile)
    cout<< "Unable to open file input.txt.\n";
    if (!outfile)
    cout<< "Unable to open file output.txt.\n";
    }
    }

    void writetitle(ofstream& outfile)
    {
    outfile<< "Title\n\n";
    }
    void writeheading(ofstream& outfile)
    {
    outfile<< "Headings\n\n";
    }
    void sortsf(snowfall validsf[])
    {
    snowfall temp;

    for (int i; i = validsf.getvalidcount(); i++)
    for (int j; j = i + 1; j++)
    if ((float(validsf.getft()) * 12 + validsf.getin()) >
    (float(validsf[j].getft()) * 12 + validsf[j].getin()))
    {
    temp = validsf;
    validsf = validsf[j];
    validsf[j] = temp;
    }
    }
    void writevalidsf(snowfall validsf[], ofstream& outfile)
    {
    for (int i=0; i = validsf.getvalidcount(); i++)
    validsf.writedata(outfile);
    }
    void writeinvalidsf(snowfall invalidsf[], ofstream& outfile)
    {
    if (invalidsf[0].getinvalidcount() != 0)
    for (int i = 0; i = invalidsf.getinvalidcount(); i++)
    outfile<< "Invalid amount of snowfall for the date, "
    << invalidsf.getdate() << endl;
    }
     
    , Dec 13, 2004
    #1
    1. Advertising

  2. Howard Guest

    What kind of help do you need? You haven't said what problems you are
    having. Does it compile? Does it crash? Does it incorrectly print out the
    latest football stats (like putting the 49ers in 1st place)??? :)

    It's a fair amount of work for someone to simply look at a program and guess
    what it is supposed to do, and whether it will actually do that. We really
    need more information from you as to what exactly is going wrong before we
    can tell you why that might be the case.

    -Howard
     
    Howard, Dec 13, 2004
    #2
    1. Advertising

  3. Guest

    This is the error messages I'm getting.

    Program4.cpp
    C:\Program Files\Microsoft Visual
    Studio\MyProjects\Program4\Program4.cpp(146) : error C2660: 'sortsf' :
    function does not take 0 parameters
    C:\Program Files\Microsoft Visual
    Studio\MyProjects\Program4\Program4.cpp(148) : error C2660:
    'writevalidsf' : function does not take 1 parameters
    C:\Program Files\Microsoft Visual
    Studio\MyProjects\Program4\Program4.cpp(149) : error C2660:
    'writeinvalidsf' : function does not take 1 parameters
    Error executing cl.exe.

    Program4.exe - 3 error(s), 0 warning(s)

    when I click on the error messge, it brings me to this line on the
    source code.

    sortsf(validsf);
    writeheadings(outfile);
    writevalidsf(validsf, outfile);
    writeinvalidsf(invalidsf, outfile);
    validsf.writetotalsf(outfile);
     
    , Dec 13, 2004
    #3
  4. Andre Kostur Guest

    wrote in news:1102958364.558876.130680
    @z14g2000cwz.googlegroups.com:

    > This is the error messages I'm getting.
    >
    > Program4.cpp
    > C:\Program Files\Microsoft Visual
    > Studio\MyProjects\Program4\Program4.cpp(146) : error C2660: 'sortsf' :
    > function does not take 0 parameters
    > C:\Program Files\Microsoft Visual
    > Studio\MyProjects\Program4\Program4.cpp(148) : error C2660:
    > 'writevalidsf' : function does not take 1 parameters
    > C:\Program Files\Microsoft Visual
    > Studio\MyProjects\Program4\Program4.cpp(149) : error C2660:
    > 'writeinvalidsf' : function does not take 1 parameters
    > Error executing cl.exe.
    >
    > Program4.exe - 3 error(s), 0 warning(s)
    >
    > when I click on the error messge, it brings me to this line on the
    > source code.
    >
    > sortsf(validsf);
    > writeheadings(outfile);
    > writevalidsf(validsf, outfile);
    > writeinvalidsf(invalidsf, outfile);
    > validsf.writetotalsf(outfile);
    >


    Oh my. Please tell me that you at least indent your code? Also, you may
    wish to take up the practice of writing small pieces of code _first_, see
    if they compile, then add more (ie: incremental development). Start
    with:

    int main()
    {
    }

    then compile.

    Then add the basic frame of your snowfall class (ie: an empty class named
    snowfall), and compile. Repeat in small steps until you get a complete
    program. As you gain experience, these small steps may get larger.
    Indentation of your code is there for your comprehension of your own code
    (and other people trying to comprehend your code....).

    A couple things to note:

    1) void main() is non-standard. use "int main()".
    2) If you write your extra functions before your main function, you have
    no need to forward-declare them. Looking at sortsf in particular, you
    declare it in main to take an object of type snowfall by value, you later
    call it without passing a parameter at all, and finally define it taking
    an array of snowfall. Make up your mind.....
    3) With a quick glance it looks like you're doing something similar with
    the other functions too.
     
    Andre Kostur, Dec 13, 2004
    #4
  5. Mike Wahler Guest

    <> wrote in message
    news:...
    > This is the error messages I'm getting.
    >
    > Program4.cpp
    > C:\Program Files\Microsoft Visual
    > Studio\MyProjects\Program4\Program4.cpp(146) : error C2660: 'sortsf' :
    > function does not take 0 parameters
    > C:\Program Files\Microsoft Visual
    > Studio\MyProjects\Program4\Program4.cpp(148) : error C2660:
    > 'writevalidsf' : function does not take 1 parameters
    > C:\Program Files\Microsoft Visual
    > Studio\MyProjects\Program4\Program4.cpp(149) : error C2660:
    > 'writeinvalidsf' : function does not take 1 parameters
    > Error executing cl.exe.
    >
    > Program4.exe - 3 error(s), 0 warning(s)


    These error messages are imo very clear: You've passed the
    wrong number of arguments when calling these functions.
    Also, your prototypes are wrong.

    The prototypes from your originial post:

    void sortsf(snowfall); /* requires one argument */
    void writevalidsf(snowfall, ofstream&); /* requires two arguments */
    void writeinvalidsf(snowfall, ofstream&); /* requires two arguments */

    You also have other problems. The actual function definitions:


    void sortsf(snowfall validsf[])
    {
    /* etc */
    }

    The prototype above does not match this function's signature.
    The number of parameters matches, but the type is wrong.
    'snowfall' and 'snowfall[]' are not the same type.

    void writevalidsf(snowfall validsf[], ofstream& outfile)
    {
    /* etc */
    }

    The prototype above does not match this function's signature.
    The number of parameters matches, but the type of the first one
    is wrong. 'snowfall' and 'snowfall[]' are not the same type.

    void writeinvalidsf(snowfall invalidsf[], ofstream& outfile)
    {
    /* etc */
    }

    The prototype above does not match this function's signature.
    The number of parameters matches, but the type of the first one
    is wrong. 'snowfall' and 'snowfall[]' are not the same type.

    Your calls to these functions in 'main()':

    sortsf(); /* no argument given */
    writevalidsf(outfile); /* only one argument given */
    writeinvalidsf(outfile); /* only one argument given */


    >
    > when I click on the error messge, it brings me to this line on the
    > source code.
    >
    > sortsf(validsf);


    Wrong number of arguments.

    > writeheadings(outfile);
    > writevalidsf(validsf, outfile);


    Wrong number of arguments.

    > writeinvalidsf(invalidsf, outfile);


    Wrong number of arguments.

    > validsf.writetotalsf(outfile);


    Fix your prototypes, and provide the correct number of arguments
    when calling your functions.

    Notes:

    1. Note that 'main()' is required to have a return type of 'int'.
    Not 'void', or any other type, but 'int'. Only.

    2. And finally, when you post code here, please use indentation.
    Without, your code is not easy to read.

    3. I recommend you consider replacing your arrays with containers
    which are more flexible and much less error prone.

    HTH,
    -Mike
     
    Mike Wahler, Dec 13, 2004
    #5
  6. Guest

    Thank you.
     
    , Dec 13, 2004
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. DP
    Replies:
    0
    Views:
    1,170
  2. Sam
    Replies:
    20
    Views:
    767
    Martijn Lievaart
    Jan 9, 2004
  3. Hemkesh
    Replies:
    1
    Views:
    372
    Nigel Wade
    Feb 20, 2009
  4. David Sudolcan
    Replies:
    7
    Views:
    2,179
    Eric Sosman
    Apr 4, 2011
  5. Andries

    I know, I know, I don't know

    Andries, Apr 23, 2004, in forum: Perl Misc
    Replies:
    3
    Views:
    262
    Gregory Toomey
    Apr 23, 2004
Loading...

Share This Page