Solved

displaying a textfile

Posted on 2003-11-07
7
308 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 100 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
[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

 
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

On Demand Webinar: Networking for the Cloud Era

Ready to improve network connectivity? Watch this webinar to learn how SD-WANs and a one-click instant connect tool can boost provisions, deployment, and management of your cloud connection.

Question has a verified solution.

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

Resolving an irritating Remote Desktop connection that stops your saved credentials from being used.
We take a look at some of the most common obstacles that IT teams run into as they work relentlessly to keep all the alarms and sirens from going off at once.
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

726 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