Solved

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

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

Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

Question has a verified solution.

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

FAQ pages provide a simple way for you to supply and for customers to find answers to the most common questions about your company. Here are six reasons why your company website should have a FAQ page
An article on effective troubleshooting
This Micro Tutorial will give you a basic overview how to record your screen with Microsoft Expression Encoder. This program is still free and open for the public to download. This will be demonstrated using Microsoft Expression Encoder 4.
This tutorial gives a high-level tour of the interface of Marketo (a marketing automation tool to help businesses track and engage prospective customers and drive them to purchase). You will see the main areas including Marketing Activities, Design …

813 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

16 Experts available now in Live!

Get 1:1 Help Now