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?
--------------------------------------------------------------------------------
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
#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;

//tabular format
cout << "Name" << "\t" << "\t";
cout << "Quarter1" << "\t";
cout << "Quarter2" << "\t";
cout << "Quarter3" << "\t";
cout << "Quarter4" << "\t";
cout << endl;
cout << "-------------------------------------------------------------------------" << endl << endl;
}
//=============================================================================================== 
Last edited on
This is my Source.cpp File:
------------------------------------
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
//C++ program that records the salaries of employees in a company during the four quarters of the year.
#include<iostream>
#include<string>

//The header file that is used for the created functions: 
#include"CSI205.h"

using namespace std;

//The beginning of our main function
int main() {
	cout << "======================================== Welcome To Our Program... ========================================" << endl;
	cout << "===========================================================================================================" << endl;

	//Asking the user to enter the name of the company.
	cout << "Enter the name of the company: ";//taken from internet
	string companyname;
	getline(cin, companyname); //used getline because it allow to enter multiple words unlike cin which allows only for one word
	cout << "Your company is: " << companyname << endl << endl;

	//Asking user to enter the number of the company's employees (number should be less than 50).
	int employeesnumb;
	cout << "Enter The Number of Employees (Number Should Be Less Than 50): ";
	cin >> employeesnumb;

	// a loop to ensure that employee's number is not greater than 50
	while (employeesnumb >= 50) {
		cout << "Number Should Be Less Than 50, Re-enter The Number of Employees: ";
		cin >> employeesnumb;
	}
	cout << endl;

	//intructions to be followed
	cout << "Please Follow The Following Instructions: " << endl;
	cout << "--------------------------------------------" << endl;
	cout << "Enter The Letter 'A' Inorder to Fill Employees Data (Name and Salary)." << endl;
	cout << "Enter The Letter 'B' Inorder to Print Employees Data In a Tabular Format." << endl;
	cout << "Enter The Letter 'C' Inorder to Get The Maximum of All Salaries In The Company." << endl;
	cout << "Enter The Letter 'D' Inorder to Get The Minimum of All Salaries In The Company." << endl;
	cout << "Enter The Letter 'E' Inorder to Get The Average of All Salaries In The Company." << endl;
	cout << "Enter The Letter 'F' Inorder to Get The Standard Deviation of All Salaries In The Company." << endl;
	cout << "Enter The Letter 'G' Give a Raise to All Employees." << endl;
	cout << "Enter The Letter 'H' Inorder to Print The Salaries of a Specific Employee Sorted In Ascending Order." << endl;
	cout << "Enter The Letter 'I' Inorder to Get The Name of The Employee That Has The Lowest Salary." << endl;
	cout << "Enter The Letter 'J' Inorder to Output a Good Bye Message and Exit The Program." << endl;
	cout << "---------------------------------------------------------------------------------------------------------" << endl << endl;

	//(i++) inside the [switch] is for the i to reach 10 and end the loop
	char choice;
	int i = 1;
	while (i <= 10) {
		cout << "Enter Your Choice: ";
		cin >> choice;
		switch (choice) {
		case 'a':
		case 'A': fillEmployees( employeename[50], salary[4][4], employeesnumb ); i++; break;
		case 'b':
		case 'B':  i++; break;
		case 'c':
		case 'C':  i++; break;
		case 'd':
		case 'D':  i++; break;
		case 'e':
		case 'E':  i++; break;
		case 'f':
		case 'F':  i++; break;
		case 'g':
		case 'G':  i++; break;
		case 'h':
		case 'H':  i++; break;
		case 'i':
		case 'I':  i++; break;
		case 'j':
		case 'J': cout << "Thank you for using our program, good bye..." << endl; system("pause"); return 0;
		default:  cout << "Sorry But Your Choice Is Invalid, Please Re-check The Choices' List Above..." << endl;

		} //ending of the switch
	} //the ending of the switch's while loop

	system("pause");
	return 0;
}
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.
Registered users can post here. Sign in or register to post.