Sequential Axcess File Help!!!

I have written code that accepts input from the user to axcess a SAF and display the information that is related to the input. It is numeric and it is not displaying the correct data. I have made sure that the user info is correct. I am missing a line or something. HELP!!
Post your code and we can help.
#include <iostream>
#include <fstream>
using namespace std;

int main()
{
ifstream inSalary;
inSalary.open("Intermediate24.txt");
int paycode = 0;
int salary = 0;

if (inSalary.is_open())
cout << "Enter Payroll Code: ";
cin >> paycode;
inSalary >> paycode >> salary;
if(paycode >= 1 && paycode <= 32)
{
cout << "Salary: " << salary << endl;
}
else
cout << "Invalid Paycode";

inSalary.close();

return 0;
}
Last edited on
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


This is the txt
The only help I have found deals with String data mostly and I have altered the code alot trying to fix it.
Try deleting the # from your txt and use space instead ( by space I mean empty space).
1 27200
2 15000
....
And so on...
See if that works.
Well, the obvious thing you're missing is a loop. It's not possible to read in everything and find out what you want while only reading two values from the file.

The second thing is that you're not handling the # delimiter correctly:

1
2
3
4
5
6
7
8
9
10
11
12
13
#include <iostream>
#include <fstream>
using namespace std ;

int main()
{
     ifstream in("Intermediate24.txt") ;

     char delimiter ;
     int payCode, salary ;
     while ( in << payCode << delimiter << salary )
          cout << payCode << ": \t" << salary << '\n' ;
}


Topic archived. No new replies allowed.