Solved

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

Posted on 2000-03-23
2
212 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: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

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

A look at what happened in the Verizon cloud breach.
Choosing a core focus or particular set of features and options can be tough. To help out, we’re going to highlight a handful of things your business needs on one of your social media pages. In other words, if one of these is missing, you should imp…
This is my first video review of Microsoft Bookings, I will be doing a part two with a bit more information, but wanted to get this out to you folks.
In this video you will find out how to export Office 365 mailboxes using the built in eDiscovery tool. Bear in mind that although this method might be useful in some cases, using PST files as Office 365 backup is troublesome in a long run (more on t…

615 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