functions and parameters

R

Richard

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;

}
 
M

Mike Wahler

Richard said:
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
 
R

Richard

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];
 
R

Richard

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.
 
R

Richard

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];
}
 
S

shailendra

Richard said:
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.
 
T

Thorsten Raasch

Richard said:
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.
 
J

Jay Nabonne

// 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
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,581
Members
45,057
Latest member
KetoBeezACVGummies

Latest Threads

Top