• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 317
  • Last Modified:

displaying a textfile

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
vyhoang
Asked:
vyhoang
  • 4
  • 3
1 Solution
 
bcladdCommented:
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
 
vyhoangAuthor Commented:
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
 
vyhoangAuthor Commented:
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
Become an Android App Developer

Ready to kick start your career in 2018? Learn how to build an Android app in January’s Course of the Month and open the door to new opportunities.

 
bcladdCommented:
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
 
vyhoangAuthor Commented:
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
 
vyhoangAuthor Commented:
nevermind i figured out what the problem was, thankyou for all you help bcladd
0
 
bcladdCommented:
Glad to be able to help. -bcl
0

Featured Post

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

  • 4
  • 3
Tackle projects and never again get stuck behind a technical roadblock.
Join Now