Functions

Questions:
-------------
1. void fillEmployees (string names [50], int salaries [50] [4], int N) that asks the user to input the names and salaries of the N employees and fills the names in the array names and the salaries in two-dimensional array salaries.
2. void printAllEmployees(string names[50], int salaries[50] [4], int N) that prints the names and salaries of all employees in a tabular format
-------------------------------------------------------------------------------
Please, I have to do these as functions but I'm having the struggle to write them and even if they work, I fail to call them in the main.
Note: these functions are in a header file.
Can anyone help me, please?
--------------------------------------------------------------------------------
[code]#include<iostream>
#include<string>
using namespace std;
/*Function Number(1): asks the user to input the names and salaries of the N employeesand fills
the names in the array namesand the salaries in a two - dimensional array salaries.*/
//===============================================================================================
void fillEmployees(int salaries[50][4], int N){
//for loop to fill only according to the employee number
for (int i = 1; i <= N; i++) {
cout << "Enter name and salaries of the employee " << i << " in the four quarters: " << endl;
//entering the names
string names;
getline(cin, names);
//entering the salaries
int salaries[50][4];
for (int i = 0; i < 1; i++)
for (int j = 0; j < 4; j++)
cin >> salaries[i][j];

}
//===============================================================================================


//Function Number(2): prints the names and salaries of all employees in a tabular format.
//===============================================================================================
void printAllEmployees(string names[50], int salaries[50][4], int N); {
for (int i = 0; i < 1; i++) {
for (int j = 0; j < 4; j++)
cout << salaries[i][j] << "\t";
cout << endl;
}
cout << endl;


}
cout << endl;

Last edited on
This is my Source.cpp File:
------------------------------------
[code]//C++ program that records the salaries of employees in a company during the four quarters of the year.
#include<iostream>
#include<string>
Last edited on
You cannot define a [normal] function inside a function. Thus move printAllEmployees(...) outside/before fillEmployees(...). Remove the trailing ;. Line 26 should look like this:

printAllEmployees(names, salaries, N);

Remove line 12 in fillEmployees(...). Change it to a paremater according to 1..
Remove line 15 in fillEmployees(...).

Line 56 in main(...) should look like this:

fillEmployees( employeename, salary, employeesnumb );

Create the variables before the loop in main(...) like so:
1
2
string employeename[50];
int salary[4][4];


Further more: The definitions of functione shouldn't be in the header files. Only the prototypes. Otherwise the linker will throw multiple definition when the header is included more than once.
Topic archived. No new replies allowed.