Solved

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

Posted on 2000-03-23
2
209 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
[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
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

Free Tool: SSL Checker

Scans your site and returns information about your SSL implementation and certificate. Helpful for debugging and validating your SSL configuration.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Read our guide on how to survive being on-call.
In order to fulfill our mission of inspiring learning in the technology community, Experts Exchange is launching a Course of the Month program. Premium and Team Account members will have access to one course per month as a part of their membership, …
Exchange organizations may use the Journaling Agent of the Transport Service to archive messages going through Exchange. However, if the Transport Service is integrated with some email content management application (such as an antispam), the admini…

749 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