Solved

I think it's a runtime error, but....

Posted on 2000-03-23
2
204 Views
Last Modified: 2010-04-16
I don't know what's wrong here. I think I'm getting a runtime error in this:

var name: string;
    numb: integer;
    wt: integer;
    AppFile: text;

procedure GETDATA (var localAppFile: text;
                   var localname: string;
                   var localnumb: integer;
                   var localwt: integer);

  begin
    readln (localAppFile, localname);
    readln (localAppFile, localnumb);
    readln (localAppFile, localwt);
  end; {GETDATA}

procedure POSITION;

    begin
      if (numb < 10) and (wt < 180) then
        writeln ('Accepted ');


      if not ((numb < 10) and (wt < 180)) then
           writeln ('Rejected ');
           writeln ('Your weight is more than the given weight ');
           writeln ('The number of cigarettes you smoke is over the limit ');
    end; {POSITION}

begin {main}
  assign (AppFile, 'A:\AppFile2.dat');
  reset (AppFile);
  while not seekeof (AppFile) do
     begin
        GETDATA (AppFile, name, numb, wt);
        POSITION;
     end;
  close (Appfile)
end.


This is what I get on the "Accepted" ones:
    "Accepted"
     "Your weight is more than the given weight"
     " The number of cigarettes you smoke is over the limit"
   
0
Comment
Question by:kazooie21
2 Comments
 

Author Comment

by:kazooie21
ID: 2650827
Adjusted points from 5 to 10
0
 

Accepted Solution

by:
Carpathia earned 10 total points
ID: 2651495
An IF statement only executes the next statement. As you can see, Rejected is only printed if the condition fails.
But the two lines after are executed everytime, as they are not part of the IF statement.

Solution:

Place a BEGIN and END around the three lines you want to execute only when the condiion fails.

But a better way would be this...


procedure POSITION;
begin
  if (numb < 10) and (wt < 180) then
    writeln ('Accepted ')
  else
  begin
    writeln ('Rejected ');
    writeln ('Your weight is more than the given weight ');
    writeln ('The number of cigarettes you smoke is over the limit ');
  end;
end; {POSITION}

Regards

0

Featured Post

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

Join & Write a Comment

HOW TO: Upload an ISO image to a VMware datastore for use with VMware vSphere Hypervisor 6.5 (ESXi 6.5) using the vSphere Host Client, and checking its MD5 checksum signature is correct.  It's a good idea to compare checksums, because many installat…
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
Here's a very brief overview of the methods PRTG Network Monitor (https://www.paessler.com/prtg) offers for monitoring bandwidth, to help you decide which methods you´d like to investigate in more detail.  The methods are covered in more detail in o…
Polish reports in Access so they look terrific. Take yourself to another level. Equations, Back Color, Alternate Back Color. Write easy VBA Code. Tighten space to use less pages. Launch report from a menu, considering criteria only when it is filled…

705 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

19 Experts available now in Live!

Get 1:1 Help Now