Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

displaying a textfile

Posted on 2003-11-07
7
Medium Priority
?
313 Views
Last Modified: 2010-04-16
I have a textfile called Inv and this is a part of my code:

Procedure CheckMinimum;
VAR
   MinStock : integer;

BEGIN
   reset (inv);
   MinStock := 0;
   Stock := 0;
   While not eof (inv) do
   BEGIN
      readln(inv, id, instock, price, min,  name);
   end;
      IF instock < min THEN
      BEGIN
         writeln('The following items have an amount less than the mininmum recommended:');
         writeln('   ID    In Stock      Minimum');
         writeln('==============================');
         writeln(id:5, instock:12, min:13);
      end;
   close(inv);
end; { CheckMinimum }


i want to display all items in the textfile that have items less the the minimum listed, my current code only displays the last item in the textfile that meets this criterea. how do i make it display all of them instead of just that one.
i would greatly appreciate any help
0
Comment
Question by:vyhoang
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 4
  • 3
7 Comments
 
LVL 11

Accepted Solution

by:
bcladd earned 300 total points
ID: 9701174
Actually, if the last line in the file were "in stock", your program would not display anything at all. Why? Because you have a loop that read the file:

   While not eof (inv) do
     BEGIN
      readln(inv, id, instock, price, min,  name);
     end;

and you have a selection statement having to do with printing:

    IF instock < min THEN
      BEGIN
         writeln('The following items have an amount less than the mininmum recommended:');
         writeln('   ID    In Stock      Minimum');
         writeln('==============================');
         writeln(id:5, instock:12, min:13);
      end;

but one is not within the other. Be very careful when indenting your lines to make sure that something is indented when it is contained within a begin/end block. You want to change your loop to read:

  while not eof(inv) do
    BEGIN
      readln(inv, id, instock, price, min,  name);
      IF instock < min THEN
      BEGIN
         writeln('The following items have an amount less than the mininmum recommended:');
         writeln('   ID    In Stock      Minimum');
         writeln('==============================');
         writeln(id:5, instock:12, min:13);
      end;
    END;

Also, you probably want to move the header printing OUT of the loop altogether (put it above the while) and just print the information for the low stock item in the if statement.
0
 

Author Comment

by:vyhoang
ID: 9704734
Procedure Transaction;
VAR
   ordera, orderb, orderc    : char;                          {1st order letter, 2nd order letter, 3rd order letter}
   ordernum, idnum, stocknum : integer;                       {ordernumber, item number, number of items sold ot returned}
   status                    : char;                          {sold or return}
   LetterS, LetterR          : integer;
BEGIN
   reset (inv);  
   rewrite (newinventory);
   WHILE NOT eoln (inv) DO
   BEGIN
      readln(inv, id, instock, price, min, name);
      reset (invup);
      WHILE NOT eoln (invup) DO
      BEGIN
         readln(invup, ordera, orderb, orderc, ordernum, idnum, status, stocknum);
         If id = idnum THEN
         BEGIN
            IF status = 'S' THEN
            BEGIN
               IF status = 'R' THEN
               BEGIN
                  LetterR := instock + stocknum;
                  writeln (newinventory, id, LetterR, price, min, name);
               end;
               LetterS := instock - stocknum;
               writeln (newinventory, id, LetterS, price, min, name);
            end;
         end;
      end;
   end;

   close(inv);
   close(newinventory);
end; { Transaction }

This is what i have to do:
Update: Update the InventoryFile with the transactions from the InventoryUpdate file. (Do not actually change the InventoryFile as this will be awkward for debugging and testing. Write to a third file called newinventory.) To make the assignment easier the Leestma InventoryUpdate file has been altered to include a sentinel value at the end of the file, so the last line is:9999999 99999 99

But why when do i run it i get no output?
0
 

Author Comment

by:vyhoang
ID: 9704794
this is the invup file:

CCI7543 1012S  2

LTB3429 1012S  7

DJS6762 1021S  9

NQT1850 1022S  1

WYP6425 1023S  4

YOK2210 1023R  2

QGM3144 1023S  1

NPQ8685 1031S  5

MAP8102 1031S 13

JRJ6335 1031S  1

UWR9386 1032S  3

TJY1913 1032S 11

YHA9464 1041S  5

SYT7493 1041S  3

FHJ1657 1042S  7

OJQ1221 1043S  8

UOX7714 1043S  2

ERZ2147 1043S  7

MYW2540 1044S  1

UKS3587 1045S  2

AAN3759 1045S  2

WZT4171 1045S 12

TYR9475 1511S  1

FRQ4184 1511S  1

TAV3604 1512S  2

DCW9363 1522S  1

EXN3964 1522R  1

OIN5524 1522S  1

EOJ8218 1522S  1

YFK0683 2011S  2

PPX4743 2012S  4

DBR1709 2013S  4

JOM5408 2013S  3

PKN0671 2013S  1

LBD8391 3011S  9

DNL6326 3012S  9

BTP5396 3013S  1

GFL4913 3013S  8

EHQ7510 3013S  7

QQL6472 3013S  5

SVC6511 3014S  4

XJQ9391 3014S  4

ONO5251 3111S  3

CXC7780 3111S  1

VGT8169 3112S  8

IMK5861 3511S  2

QHR1944 3511S  1

ZPK6211 4011S  2

VDZ2970 4012S  6

BOJ9069 5011S  6

MNL7029 5011S  9

MRG8703 5021S 10

DEM9289 5021S  1

BXL1651 5031S  2

VAF8733 6111S 65

UYI0368 7011S  2

VIZ6879 8011S 16

GXX9093 8011S 19

HHO5605 8021S 41

BOL2324 8021S 49

PAG9289 8023S 15

MDF5557 8023S 17

IQK3388 8024S 12

OTB1341 8024S 28

SVF5674 8031S 24

ZDP9484 8031S 15

OSY8177 8032S 15

GJQ0185 8032S  8

VHW0189 8041S 20

WEU9225 8041S  6

YJO3755 8041S  8

9999999 99999  9
0
New feature and membership benefit!

New feature! Upgrade and increase expert visibility of your issues with Priority Questions.

 
LVL 11

Expert Comment

by:bcladd
ID: 9705403
I am not going to work through your homework for you. What, exactly, is your question about the code you posted? What does it do that is not as indicated in the assignment?

-bcl
0
 

Author Comment

by:vyhoang
ID: 9706009
when i run the program everything works but when it perfroms the prodedure transaction, it seems that it doesn't write the outout file for the new data, and i don't understand what the problem is within the code. if you could can you just give me a hint as to how to fix this
0
 

Author Comment

by:vyhoang
ID: 9706069
nevermind i figured out what the problem was, thankyou for all you help bcladd
0
 
LVL 11

Expert Comment

by:bcladd
ID: 9706799
Glad to be able to help. -bcl
0

Featured Post

How to Use the Help Bell

Need to boost the visibility of your question for solutions? Use the Experts Exchange Help Bell to confirm priority levels and contact subject-matter experts for question attention.  Check out this how-to article for more information.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

One of the most important things in an application is the query performance. This article intends to give you good tips to improve the performance of your queries.
With so many activities to perform, Exchange administrators are always busy in organizations. If everything, including Exchange Servers, Outlook clients, and Office 365 accounts work without any issues, they can sit and relax. But unfortunately, it…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
Suggested Courses

610 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