Access File Payroll Code Program, need help

Creating a program that allows the user to enter a payroll code, the program searches for it and displays its corresponding salary amount. Should display this amount and allow the user to re enter a new code. I feel like I may be getting close to doing this right but I can't seem to get it to work, and if someone could get it working/help me get it working I would appreciate it. Access file contents will be underneath the code.

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
  // Chapter 14. Ex 24.cpp : Defines the entry point for the console application.
//

#include <iostream>
#include <string>
#include <fstream>
using namespace std;


int main()
{
	//variables
	int salary;
	string line;
	string search;
	ifstream inFile;
	int code;

	//chooses salary based on payroll code chosen
	if ()

		//opens .txt file containing payroll codes and their corosponding salaries
	inFile.open("Intermediate24.txt");

	//checks if file is open and ends program if it is unable to
	if (!inFile)
	{
		cout << "Unable to open file" << endl;
		exit(1);
	}

	//enters code
	cout << "Enter a payroll code ";
	cin >> code;
	
	//while loop checks if code is valid and displays salary for that code
	size_t pos;
	while (inFile.good())
	{
		getline(inFile, line); // get line from file
		pos = line.find(search); // search
		while (pos != string::npos) // string::npos is returned if string is not found
		{
			cout << "Salary is: " << salary << endl;
		}
	}
	return 0;
	system("PAUSE");
}



Access file:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
1#27200
2#15000
3#23000
4#12000
5#25500
5#18400
6#18400
7#19500
8#32000
9#29000
10#16500
20#65000
21#65500
22#70200
23#71000
24#71100
25#72000
30#83000
31#84000
32#90000 
Here is some code to read and parse the file. It reads the integer code, then one character, which should be the '#', the another integer. It prints out the result after checking to ensure that that character is '#'. Make sure you understand how this code works. Then add code to print out the salary for code that was entered.
1
2
3
4
5
6
7
8
9
    char ch;
    int code, salary;
    while (cin >> code >> ch >> salary) {
        if (ch != '#') {
            cout << "trouble paring line\n";
        } else {
            cout << code << ": " << salary << '\n';
        }
    }

Where in the program should I put this?
Topic archived. No new replies allowed.