functions and parameters

Discussion in 'C++' started by Richard, Oct 21, 2005.

  1. Richard

    Richard Guest

    I got two error saying "Error 2 error C2064: term does not evaluate to a
    function taking 2 arguments" from the code below. I don't understand why or
    what is wrong. Can anyone tell me what I did wrong. I am to C++. Thanks

    #include <iostream>

    #include <iomanip>

    #include <string>

    //#include <stdlib>

    //#include <math>

    using namespace std;

    //function phototype

    int NumberOfEmployee (void);

    int DaysOut(int);

    int AverageDaysOut(int, int);

    // variable declarations

    //int NumberOfEmployee, TotalDaysOut, DaysOut;

    //float AverageDaysOut;

    void main()

    { int NumberOfEmployee, TotalDaysOut;

    int AverageDaysOut;

    //cout<<setprecision(2);

    //cout.setf(ios::fixed | ios::showpoint);

    NumberOfEmployee=NumberOfEmployee();

    TotalDaysOut=DaysOut(NumberOfEmployee);

    AverageDaysOut=AverageDaysOut(NumberOfEmployee, TotalDaysOut);

    cout<<"The number of Employee in your company is "<<NumberOfEmployee<<endl;

    cout<<"The total number of days all of your company's employee missed is
    "<<TotalDaysOut<<endl;

    cout<<"The average days missed for each employee is "<<AverageDaysOut<<endl;

    }

    int NumberOfEmployee (void)

    {

    int NumberOfEmployee;


    cout<<"How many employees does your company has?: ";

    cin>>NumberOfEmployee;

    while (NumberOfEmployee < 1)

    {

    cout<<"Enter the number of employees greater 1: ";

    cin>>NumberOfEmployee;

    }

    return NumberOfEmployee;

    }

    int DaysOut(int NumberOfEmployee)

    {

    int TotalDaysOut, DaysOut;

    for (int count =1; count <= NumberOfEmployee; count++)

    {

    cout<<"How many days did employee "<<count<<" missed work during the past
    year? : ";

    cin>>DaysOut;

    while(DaysOut < 0)

    {

    cout<<"Enter a positive days out: ";

    cin>>DaysOut;

    }

    TotalDaysOut +=DaysOut;

    return TotalDaysOut;

    }

    }

    int AverageDaysOut(int NumberOfEmployee, int TotalDaysOut)

    {

    int AverageDaysOut;

    AverageDaysOut = TotalDaysOut/NumberOfEmployee;

    return AverageDaysOut;

    }
     
    Richard, Oct 21, 2005
    #1
    1. Advertising

  2. Richard

    Mike Wahler Guest

    "Richard" <> wrote in message
    news:...
    >I got two error saying "Error 2 error C2064: term does not evaluate to a
    >function taking 2 arguments" from the code below. I don't understand why
    >or what is wrong. Can anyone tell me what I did wrong. I am to C++.
    >Thanks


    See below

    >
    > #include <iostream>
    >
    > #include <iomanip>
    >
    > #include <string>
    >
    > //#include <stdlib>
    >
    > //#include <math>
    >
    > using namespace std;
    >
    > //function phototype
    >
    > int NumberOfEmployee (void);
    >
    > int DaysOut(int);
    >
    > int AverageDaysOut(int, int);
    >
    > // variable declarations
    >
    > //int NumberOfEmployee, TotalDaysOut, DaysOut;
    >
    > //float AverageDaysOut;
    >
    > void main()
    >
    > { int NumberOfEmployee, TotalDaysOut;
    >
    > int AverageDaysOut;
    >
    > //cout<<setprecision(2);
    >
    > //cout.setf(ios::fixed | ios::showpoint);
    >
    > NumberOfEmployee=NumberOfEmployee();
    >
    > TotalDaysOut=DaysOut(NumberOfEmployee);
    >
    > AverageDaysOut=AverageDaysOut(NumberOfEmployee, TotalDaysOut);
    >
    > cout<<"The number of Employee in your company is
    > "<<NumberOfEmployee<<endl;
    >
    > cout<<"The total number of days all of your company's employee missed is
    > "<<TotalDaysOut<<endl;
    >
    > cout<<"The average days missed for each employee is
    > "<<AverageDaysOut<<endl;
    >
    > }
    >
    > int NumberOfEmployee (void)
    >
    > {
    >
    > int NumberOfEmployee;
    >
    >
    > cout<<"How many employees does your company has?: ";
    >
    > cin>>NumberOfEmployee;
    >
    > while (NumberOfEmployee < 1)
    >
    > {
    >
    > cout<<"Enter the number of employees greater 1: ";
    >
    > cin>>NumberOfEmployee;
    >
    > }
    >
    > return NumberOfEmployee;
    >
    > }
    >
    > int DaysOut(int NumberOfEmployee)
    >
    > {
    >
    > int TotalDaysOut, DaysOut;
    >
    > for (int count =1; count <= NumberOfEmployee; count++)
    >
    > {
    >
    > cout<<"How many days did employee "<<count<<" missed work during the past
    > year? : ";
    >
    > cin>>DaysOut;
    >
    > while(DaysOut < 0)
    >
    > {
    >
    > cout<<"Enter a positive days out: ";
    >
    > cin>>DaysOut;
    >
    > }
    >
    > TotalDaysOut +=DaysOut;
    >
    > return TotalDaysOut;
    >
    > }
    >
    > }
    >
    > int AverageDaysOut(int NumberOfEmployee, int TotalDaysOut)
    >
    > {
    >
    > int AverageDaysOut;
    >
    > AverageDaysOut = TotalDaysOut/NumberOfEmployee;
    >
    > return AverageDaysOut;
    >
    > }


    You're in serious need of some good books and/or
    paying attention in class. :)

    #include <iostream>
    #include <ostream>

    using namespace std;

    int NumberOfEmployee (void);
    int DaysOut(int);
    double AverageDaysOut(int, int);

    int main()
    {
    int NumOfEmployee(0);
    int TotalDaysOut(0);
    double AvgDaysOut(0);

    NumOfEmployee = NumberOfEmployee();
    TotalDaysOut = DaysOut(NumOfEmployee);
    AvgDaysOut = AverageDaysOut(NumOfEmployee, TotalDaysOut);

    cout << "The number of Employee in your company is "
    << NumOfEmployee << endl;

    cout << "The total number of days all of "
    "your company's employee missed is "
    << TotalDaysOut << endl;

    cout << "The average days missed for each employee is "
    << AvgDaysOut << endl;

    return 0;
    }

    int NumberOfEmployee (void)
    {
    int NumOfEmployee(0);

    cout << "How many employees does your company has?: ";
    cin >> NumOfEmployee;

    while (NumOfEmployee < 1)
    {
    cout << "Enter the number of employees greater 1: ";
    cin >> NumOfEmployee;
    }

    return NumOfEmployee;
    }

    int DaysOut(int NumOfEmployee)
    {
    int TotalDaysOut(0);
    int daysOut(0);

    for (int count = 1; count <= NumOfEmployee; count++)
    {
    cout << "How many days did employee " << count
    << " missed work during the past year? : ";

    cin >> daysOut;

    while(daysOut < 0)
    {
    cout << "Enter a positive days out: ";
    cin >> daysOut;
    }

    TotalDaysOut += daysOut;

    }

    return TotalDaysOut;
    }

    double AverageDaysOut(int NumOfEmployee, int TotalDaysOut)
    {
    return static_cast<double>(TotalDaysOut) / NumOfEmployee;
    }

    -Mike
     
    Mike Wahler, Oct 21, 2005
    #2
    1. Advertising

  3. Richard

    Richard Guest

    I got a pretty bad professor and a pretty old book. I got one more
    question. I need to create a function which prompt user to enter any
    particular month in the year such as January, March or ect. I need to
    validate the Month entered. If the user entered Match instead of March, I
    need to print out a message telling the user to try again. So far, I can
    think of a way to do this. Can you guys me a method and I will try to write
    the code. Here is how i do it so far. Thanks.

    #include <iostream>

    #include <iomanip>

    #include <string>

    #include <stdlib.h>

    using namespace std;

    // function phototype

    char GetMonth (void);

    int main()

    {



    GetMonth();

    }

    char GetMonth(void)

    {

    cout<<"What month do you need to calculate customer usage charge? :";

    cin>>Month;

    // validation of month go here, but I cannot find a method

    return Month[12];
     
    Richard, Oct 21, 2005
    #3
  4. Richard

    Richard Guest

    >>>>
    int NumOfEmployee(0);
    int TotalDaysOut(0);
    double AvgDaysOut(0);
    >>>>


    Why do you the 0 inside the parenthesis and why is the parenthesis there? I
    don't get this point. please help. My book does not do anything like that.
     
    Richard, Oct 21, 2005
    #4
  5. Richard

    Richard Guest

    the code was not correct here is the correct one for the month function:

    #include <iostream>

    #include <iomanip>

    #include <string>


    using namespace std;

    // function phototype
    char GetMonth (void);
    // variable declaration
    char Choice ,Month[12];

    char January[12]="January",
    February[12]="February",March[12]="March",April[12]="April";

    char
    May[12]="May",June[12]="June",July[12]="July",August[12]="August",September[12]="September";

    char October[12]="October", November[12]="November",December[12]="December";


    int main()

    {



    GetMonth();

    }

    char GetMonth(void)

    {

    cout<<"What month do you need to calculate customer usage charge? :";

    cin>>Month;

    // validation of month go here, but I cannot find a method

    return Month[12];
    }
     
    Richard, Oct 21, 2005
    #5
  6. Richard

    shailendra Guest

    Richard wrote:
    > I got two error saying "Error 2 error C2064: term does not evaluate to a
    > function taking 2 arguments" from the code below. I don't understand why or
    > what is wrong. Can anyone tell me what I did wrong. I am to C++. Thanks
    >
    > #include <iostream>
    >
    > #include <iomanip>
    >
    > #include <string>
    >
    > //#include <stdlib>
    >
    > //#include <math>
    >
    > using namespace std;
    >
    > //function phototype
    >
    > int NumberOfEmployee (void);
    >
    > int DaysOut(int);
    >
    > int AverageDaysOut(int, int);
    >
    > // variable declarations
    >
    > //int NumberOfEmployee, TotalDaysOut, DaysOut;
    >
    > //float AverageDaysOut;
    >
    > void main()
    >
    > { int NumberOfEmployee, TotalDaysOut;
    >
    > int AverageDaysOut;
    >
    > //cout<<setprecision(2);
    >
    > //cout.setf(ios::fixed | ios::showpoint);
    >
    > NumberOfEmployee=NumberOfEmployee();
    >
    > TotalDaysOut=DaysOut(NumberOfEmployee);
    >
    > AverageDaysOut=AverageDaysOut(NumberOfEmployee, TotalDaysOut);
    >
    > cout<<"The number of Employee in your company is "<<NumberOfEmployee<<endl;
    >
    > cout<<"The total number of days all of your company's employee missed is
    > "<<TotalDaysOut<<endl;
    >
    > cout<<"The average days missed for each employee is "<<AverageDaysOut<<endl;
    >
    > }
    >
    > int NumberOfEmployee (void)
    >
    > {
    >
    > int NumberOfEmployee;
    >
    >
    > cout<<"How many employees does your company has?: ";
    >
    > cin>>NumberOfEmployee;
    >
    > while (NumberOfEmployee < 1)
    >
    > {
    >
    > cout<<"Enter the number of employees greater 1: ";
    >
    > cin>>NumberOfEmployee;
    >
    > }
    >
    > return NumberOfEmployee;
    >
    > }
    >
    > int DaysOut(int NumberOfEmployee)
    >
    > {
    >
    > int TotalDaysOut, DaysOut;
    >
    > for (int count =1; count <= NumberOfEmployee; count++)
    >
    > {
    >
    > cout<<"How many days did employee "<<count<<" missed work during the past
    > year? : ";
    >
    > cin>>DaysOut;
    >
    > while(DaysOut < 0)
    >
    > {
    >
    > cout<<"Enter a positive days out: ";
    >
    > cin>>DaysOut;
    >
    > }
    >
    > TotalDaysOut +=DaysOut;
    >
    > return TotalDaysOut;
    >
    > }
    >
    > }
    >
    > int AverageDaysOut(int NumberOfEmployee, int TotalDaysOut)
    >
    > {
    >
    > int AverageDaysOut;
    >
    > AverageDaysOut = TotalDaysOut/NumberOfEmployee;
    >
    > return AverageDaysOut;
    >
    > }


    Your code is so ugly, I dont even feel like looking into it.
     
    shailendra, Oct 21, 2005
    #6
  7. Richard wrote:
    > >>>>

    > int NumOfEmployee(0);
    > int TotalDaysOut(0);
    > double AvgDaysOut(0);
    >
    > Why do you the 0 inside the parenthesis and why is the parenthesis there? I
    > don't get this point. please help. My book does not do anything like that.


    The code
    int i(0);
    initializes the integer i with zero, i.e., the constructor of the class
    int is called. For integral types like "int" or "double", this syntax
    should essentially be equivalent with
    int i=0;
    The point is that, using the syntax "C c(x);", where C is a class and x
    an instance of C, one usually saves one default constructor call. This
    is due to the fact that in "C c = x;", the object c is initialized first
    with its default constructor, and after that the corresponding
    =-operator is called. However, a quantitative benefit will only show up
    when more complicated classes C than integral types are used.
     
    Thorsten Raasch, Oct 21, 2005
    #7
  8. Richard

    Default User Guest

    Richard wrote:

    > I got a pretty bad professor


    You're kind of stuck with this, unless you drop the course.

    > and a pretty old book.


    This you can fix. I suggest Accelerated C++ by Koenig and Moo.



    Brian

    --
    Please quote enough of the previous message for context. To do so from
    Google, click "show options" and use the Reply shown in the expanded
    header.
     
    Default User, Oct 21, 2005
    #8
  9. Richard

    Jay Nabonne Guest

    On Fri, 21 Oct 2005 00:17:55 -0500, Richard wrote:

    > // variable declaration
    > char Choice ,Month[12];
    >
    > char January[12]="January",
    > February[12]="February",March[12]="March",April[12]="April";
    >
    > char
    > May[12]="May",June[12]="June",July[12]="July",August[12]="August",
    > September[12]="September";
    >
    > char October[12]="October", November[12]="November",December[12]="December";
    >


    Having all the month names exactly 12 characters long doesn't really make
    sense. But having said that, you probably don't want separate arrays for
    each month name anyway. Make Month an array of characters strings; then
    you can index into it to get the month name.

    const char* Month[] =
    {
    "January",
    "February",
    "March",
    // Add the rest of the month names here...
    };

    - Jay
     
    Jay Nabonne, Oct 21, 2005
    #9
    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. Jonck van der Kogel
    Replies:
    2
    Views:
    1,010
    Jonck van der Kogel
    May 27, 2004
  2. Xiangliang Meng
    Replies:
    1
    Views:
    1,665
    Victor Bazarov
    Jun 21, 2004
  3. Jason
    Replies:
    2
    Views:
    558
    Jonathan Mcdougall
    May 13, 2006
  4. kito
    Replies:
    2
    Views:
    443
  5. Florian Loitsch
    Replies:
    11
    Views:
    264
    Michael Winter
    Mar 15, 2005
Loading...

Share This Page