Having trouble help

I need help with creating a program that allows the user to enter a payroll code. The program should search for the payroll code in the file and then display the appropriate salary. If the payroll code is not in the file, the program should display an appropriate message. Use a sentinel value to end the program. Test the program using the following payroll codes: 10, 24, 55, 32, and 6. Stop the program by entering your sentinel value.

the file data

1#27200
2#15000
3#23000
4#12000
5#25500
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

i have done the codes but the only thing i cant figure out how to implement the codes from the file in the program ...any help pleease

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

int main()
{
//displays the payrolls stored in the Intermediate24.txt
string payRoll = "";
string code = "";
int userCode = 0;

//create file object and open the file
ifstream inFile;
inFile.open("Intermediate24.txt", ios::in);


//determine whether the file was opened
if (inFile.is_open())
{
//enter a payroll code
cout << "Please enter a code: ";
cin >> userCode;

//read a code
getline(inFile, code, '#');
getline(inFile, payRoll);

while (!inFile.eof())
{
if(userCode == code)
{
//display the payroll
cout << code << "." <<
payRoll << endl;

//read another code
getline(inFile, code, '#');
getline(inFile, payRoll);

}//end if

}//end while

//close the file
inFile.close();
}
else
cout << "File could not be opened" << endl;
//end if

system("pause");
return 0;
} //end of main function
changing my codes to

using namespace std;

int main()
{
//displays the payrolls stored in the Intermediate24.txt
string payRoll = "";
string code = "";

//create file object and open the file

ifstream inFile;
inFile.open("Intermediate24.txt", ios::in);

//enter a payroll code
cout << "Please enter a code: ";
cin >> code;

//determine whether the file was opened
if (inFile.is_open())
{
//read a code
getline(cin, code);
getline(inFile, payRoll);


while (!inFile.eof())
{
//display the payroll
cout << code << "." <<
payRoll << endl;

//read another code
getline(cin, code);
getline(inFile, payRoll);

}//end while

//close the file
inFile.close();
}
else
cout << "File could not be opened" << endl;
//end if

system("pause");
return 0;
} //end of main function
anyy suggestion
It's easier for us to help you if you:
1) Supply your code wrapped in code tags. This is the button on the right that looks like <>. Highlight your code and press that, or put [code] at the start of your code and [/code] at the end of it.

2) Supply us with any errors you're encountering. If you supply your complete code along with any compiler errors, it's easier for us to locate the line in question, evaluate it, and help you correct the issues.

3) Supply us with the desired output and your output. Obviously if we can see there is a difference between the two, we can help isolate the problem and help you correct it.

4) Supply us with specific lines of code that you feel are causing problems in your code. We like things to be simple, so the less code we have to sift through just to find something like you're missing a semicolon or you're doing an assignment instead of a comparison, it helps us provide quicker service.

We're not lazy, and a lot of us will go above and beyond to help someone. We're all coders after all and we like to see each other succeed. But we can't all afford to spend several hours on a simple program unless we're really bored. There are plenty of new members, and old ones, that need help and the ones that make it the easiest for us tend to get the quickest replies and in turn, quicker solutions to their problems.
my problem is how to declare the number of line in the file in my program
we don't understand what your problem here.

u just want to read your file input ?
then display them out without the # sign?
yes want to read my data file but got stucked on this one....

and i dont know if there is any erros on my codes
well it seems no help here......
example.

u want to read without #

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
int main(){
     int numbers[100];
     long integers[100];
     int i = 0;

     ifstream inFile;
     inFile.open("Intermediate24.txt");
 
     if( inFile.fail() )
           cout << "Fail to open file ! " << endl;
 
     if( inFile.is_open() ){
           while( !inFile.eof() ){
                 inFile >> number[i];
                 inFile.ignore( 1,'#' );
                 inFile >> integers[i];
                 inFile.ignore(1,'\n');
                 i++;
           }
     }

    //...Do your output staff . i only teach how to store to the array Basic concept
    system( "pause" );
    return 0;
}


Topic archived. No new replies allowed.