Solved

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

Posted on 2000-03-23
2
210 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: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering 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

Suggested Solutions

Title # Comments Views Activity
VB.Net code to pascal 1 401
Capture cookies with delphi 5 1,049
How to capture screen window of a process 4 424
Embarcadero Interbase 9 787
Dramatic changes are revolutionizing how we build and use technology. Every company is automating, digitizing, and modernizing operations. We need a better, more connected way to work together as teams so we can harness the insights from our system…
We asked our MSP customer base what their favorite tools were and how they help them serve clients. We focused our questions on favorite tools in the following categories: >PSA tools >RMM tools >Alert management tools >Communication tools and Mo…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

710 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