I have three arrays: a string, an int, and a double. I need to output the contents of them by calling them from the main function to another function. When I try to build the program, there is an error saying "identifier not found" for displayEmployeeInformation. Here is my code:
#include <iostream>
#include <string>
using namespace std;
const int numEmp = 5;
string names [numEmp];
int ages [numEmp];
double salaries [numEmp];
int main () {
const int numEmp = 5;
string names [numEmp];
int ages [numEmp];
double salaries [numEmp];
for (int i = 0; i < numEmp; i++) {
cout << "Enter Employee #" << i+1 << " Name: ";
cin >> names [i];
cout << "Enter Employee #" << i+1 << " Age: ";
cin >> ages [i];
cout << "Enter Employee #" << i+1 << " Salary: ";
cin >> salaries [i];
}
displayEmployeeInformation (names, ages, salaries, 5);
getchar();
getchar();
return 0;
}
int displayEmployeeInformation (string names [], int ages [], double salaries [], int size) {
for (int x = 0; x < numEmp; x++) {
cout << "Employee #" << x+1 << " Name: " << names [x] << ", Age: " << ages [x] << ", Salary: " << salaries [x];
}
return 0;
}
You need to add a function prototype for the function. Put this line
int displayEmployeeInformation (string names [], int ages [], double salaries [], int size);
above
int main()
.Alternatively, put the entire function definition above
int main()
.