Solved

Should I put the A:

Posted on 2000-03-08
9
152 Views
Last Modified: 2010-04-16
Here's is my program:

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

begin
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);
end;{while}
close (fileA);
close (fileB)
end.

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?
0
Comment
Question by:kazooie21
  • 5
  • 3
9 Comments
 
LVL 3

Expert Comment

by:Alisher_N
ID: 2599535
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
0
 
LVL 3

Expert Comment

by:Alisher_N
ID: 2599541
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
0
 
LVL 47

Expert Comment

by:dbrunton
ID: 2599558
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.
0
 
LVL 3

Expert Comment

by:Alisher_N
ID: 2599733
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
0
How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

 
LVL 47

Expert Comment

by:dbrunton
ID: 2599780
Alisher_N

Correct.  He's getting disk errors.  By making sure the disk is NOT write protected we eliminate one possible source.
0
 
LVL 3

Expert Comment

by:Alisher_N
ID: 2599809
we don't know actually where are his files and which ones on floppy or no ;-)...
0
 

Author Comment

by:kazooie21
ID: 2602885
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?
0
 
LVL 47

Accepted Solution

by:
dbrunton earned 5 total points
ID: 2603617
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.
0
 
LVL 3

Expert Comment

by:Alisher_N
ID: 2603762
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...
0

Featured Post

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

A Short Story about the Best File Recovery Software – Acronis True Image 2017
Find out what the Office 365 disclaimer function is, why you would use it and its limited ability to create Office 365 signatures.
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
When you create an app prototype with Adobe XD, you can insert system screens -- sharing or Control Center, for example -- with just a few clicks. This video shows you how. You can take the full course on Experts Exchange at http://bit.ly/XDcourse.

746 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now