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.
// Chapter 14. Ex 24.cpp : Defines the entry point for the console application.
//
#include <iostream>
#include <string>
#include <fstream>
usingnamespace 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");
}
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.