Compilation error

Z

zfareed

This is my program using a struct and an array and an attempt to pass
the array to a function. What does this compilation error mean?
#include <iostream>
#include <iomanip>

using namespace std;

struct Employee
{
int age;
int id;
float salary;
};

void PrintEmployee(Employee,int);
int main()
{ Employee employee[2];
employee[0].age = 30;
employee[0].id = 30042554;
employee[0].salary = 5000.00;

employee[1].age = 45;
employee[1].id = 40041002;
employee[1].salary = 70000.00;

PrintEmployee(employee,2);

system("pause");
return 0;
}

void PrintEmployee(Employee employee[],int length)
{
cout << "EmployeeID " << " Age " << " " << " Salary "
<< endl;
cout << "------------------------------" << endl;
cout << endl;
for(int i=0;i< length;i++)
{
cout << employee.id << " " ;
cout << employee.age<< " " ;
cout << setw(8) << fixed << setprecision(2) <<
employee.salary<< " " << endl;
}
}

\My Documents\C++\projects\lab4.cpp conversion from `Employee*' to non-
scalar type `Employee' requested
 
M

Michael

This is my program using a struct and an array and an attempt to pass
the array to a function. What does this compilation error mean?

void PrintEmployee(Employee,int);
int main()
{ ....
PrintEmployee(employee,2);
}

void PrintEmployee(Employee employee[],int length) .. . .

\My Documents\C++\projects\lab4.cpp conversion from `Employee*' to non-
scalar type `Employee' requested

Your first mention of PrintEmployee uses Employee as the type of its
first argument, your second uses Employee[]. You need to (pick the
right one and) be consistent.

Michael
 
G

Gianni Mariani

This is my program using a struct and an array and an attempt to pass
the array to a function. What does this compilation error mean? ....
....
Notice this decl below:
void PrintEmployee(Employee,int);
....
and this definition:
void PrintEmployee(Employee employee[],int length) ....

\My Documents\C++\projects\lab4.cpp conversion from `Employee*' to non-
scalar type `Employee' requested

Your defining a different function than you;re declaring.
 
J

John Harrison

Michael said:
On Feb 17, 1:37 pm, (e-mail address removed) wrote:


Your first mention of PrintEmployee uses Employee as the type of its
first argument, your second uses Employee[]. You need to (pick the
right one and) be consistent.

Michael

As Michael says you are being inconsistent, first you said

void PrintEmployee(Employee,int);

then you said

void PrintEmployee(Employee[],int);

There is another way which may be a good thing for newbies. If you write
the PrintEmployee function first and the main function second then there
is no need to write a prototype for PrintEmployee and so there is no
possibility of inconsistency. I.e.

void PrintEmployee(Employee employee[], int length)
{
...
}

int main()
{
...
PrintEmployee(employee, 2);
}

john
 

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,776
Messages
2,569,602
Members
45,182
Latest member
BettinaPol

Latest Threads

Top