I need to add in my code the computation of employee payroll?

Hi! i need help in my code,so here's my problem. How can I write in my code the basic pay of the employee will be computed based on his position, clerk is 120 per hour, supervisor is 150 per hour and manager is 550 per hour. Overtime pay will be computed as the rate per hour plus 30% of the rate. Tax is 2% of the gross income; SSS is 3% of the Gross and Phil health is 1.5% of the Gross Income. Net income is the sum of earnings minus deductions.
What Changes is needed and to add the formula above?
Thank You.
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
 #include <iostream>
#include <string>
#include <fstream> 

using namespace std;

int main(){
	ifstream inFile; //declare ifstream as inFile and ofstream as outFile
	ofstream outFile;

	string name, add, no, pos, id, employeeSearch; //declare user inputs as string
	int choice;
	char newEmployeeChoice;

	outFile.open("employee.txt", ios::app); 

	cout << "To Enter Employee Registration, press 1 & " << endl; 
	cout << "for Employee Payroll,press 2:  ";
	cin >> choice;

	if (choice == 1){ 
		do{
			cout << "Employee ID: "; 
			cin >> id;
				getline(cin, id);
			cout << "Name: "; 
			
			getline(cin, name);

			cout << "Address: "; 
		
			getline(cin, add);

			cout << "Contact No.: ";
		    cin>>no;
		    getline(cin, no);
			cout << "Position: "; 
			
			getline(cin, pos);

			outFile << id << "\t" << name << "\t" << add << "\t" << no << "\t" << pos << endl; 

			cout << "\nWould you like to enter in another employee (y/n): "; 
			cin >> newEmployeeChoice;
		} while (newEmployeeChoice == 'Y' || newEmployeeChoice == 'y');
	}
	else if (choice == 2){
		outFile.close(); 
		inFile.open("employee.txt"); 

		cout << "Please Enter Employee ID: "; 
		cin >> employeeSearch;

		while (getline(inFile, id, '\t'), 
			getline(inFile, name, '\t'),
			getline(inFile, add, '\t'),
			getline(inFile, no, '\t'),
			getline(inFile, pos, '\n'))

		if (employeeSearch == id){ 
			cout << "\nEmployee ID: " << id << endl;
			cout << "Name: " << name << endl;
			cout << "Address: " << add << endl;
			cout << "Contact No.: " << no << endl;
			cout << "Position:" << pos << endl;
		}
		else
		{
            cout<<"Employee not found"<<endl;
            }

		inFile.close(); 
	}

	system("pause");
	return 0;
}
Last edited on
Use f.e. a std::map (see http://www.cplusplus.com/reference/map/map/). Map position to basic pay:

typedef std::string PositionAsString;
typedef double BasicPay;
typedef std::map<PositionAsString, BasicPay> Position2Pay;

Have a look at the given reference page for details of accessing, adding or manipulating maps and their entries.

May be you want to write some functions getting the employees position as input and calculating and returning the expected information.
Topic archived. No new replies allowed.