Should I put the A:

Here's is my program:

var name: string;
      wage : real;
      years : integer;
      fileA, fileB: text;

assign (fileA, 'salary.dat');
assign (fileB, 'salary2.dat');
reset (fileA);
rewrite (fileB);
while not seekeof (fileA) do
begin {while}
     readln (fileA, name);
    readln (fileA, wage);
    readln (fileA, years);
years := years + 1;
       if years >= 10 then
             wage := wage + 30
       else wage := wage + 15
writeln (fileB, name);
writeln (fileB, wage);
writeln (fileB, years);
close (fileA);
close (fileB)

If I do this: assign (fileA, 'A:salary.dat');
                   assign (fileB, 'A:salary2.dat');

I get a runtime error, however, if I don't put the A: then I get a message saying it can't fileA.

P.S. Do I need to make a file for salary2.dat or does TP do that anyway?
Who is Participating?
If you declared wages as real this what you will get.  You are looking at an exponent this is the +E04.  There is nothing wrong in what you have got, it is saving it correctly.

Try using integer or longint for your variable type if you want to see something more understandable.
when you put 'A:' program tries to open existing file on A drive
if you use onle 'salary.dat' name program tries to open that file in current drive and current directory. if you use 'reset()' this means that file MUST exist, so make a sample file first, put it somewhere and use this particular path+filename in 'assign' call
for 'salary2' which is assigned to fileB in your example you use 'rewrite' and this procedure creates new file ALWAYS, even if file exists it OVEWRITTEN again
Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Go as per Alisher_N

might need assign(fileA, 'A:\salary.dat');

Assuming that salary.dat is not inside any folder in A: - for example it is not inside A:\wages

Your floppy disk needs to be in A: when you run the program and salary.dat needs to be on the disk.  Disk also needs to be NOT write protected.
to dbrunton:

why NOT write protected ? if we're talking about first file
assign( fileA, 'a:\salary.dat' );

he tries only read it, so it will work for any floppy disk... second file fileB of course must be available for write

Correct.  He's getting disk errors.  By making sure the disk is NOT write protected we eliminate one possible source.
we don't know actually where are his files and which ones on floppy or no ;-)...
kazooie21Author Commented:
Ok, I did that and the program runs. I opened up the salary2.dat file and found this for the wage:

103000000000+E04 (That's not exact, but they were in that format).

I declared the wage as real. What's the deal?
if you want to output a real vaule in more convenient way you can use
writeln( myfile, X:8:2 );
where 8 - total number of digits
      2 - after decimal point

but are you going to browse that file manually ? if not it doesn't matter - when you read it back your program will get proper value...
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.