Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Getting error in statement in both programs

Posted on 2000-03-25
2
Medium Priority
?
303 Views
Last Modified: 2010-04-16
I'm getting an error in statement in both of these. The error in statement occurs at the else in both of these.

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 ');
      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}

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.

****************************************
var state: string;
    capital : string;
    Statefile: text;
    tries: integer;
    guess: string;

procedure GETDATA (var localStatefile: text;
                   var localstate: string;
                   var localcapital: string);

   begin
      readln (localStatefile, localstate);
      readln (localStatefile, localcapital);
   end; {GETDATA}

procedure GUESS_CAPITAL (var tries: integer;
                         guess: string);

   begin{GUESS_CAPITAL}
     tries := 0;
     repeat
       tries := tries + 1;
       write ('Give capital of ', state, ' ' );
       readln (guess)
     until (guess = capital) or (tries <= 4);
      if guess = capital then
        writeln ('Nice work.  You got it on try ', tries);
      else
          begin{until}
           writeln ('You did not get it in 4 tries or less');
           writeln ('The correct answer is ' , capital)
          end;{until}
   end;{GUESS_CAPITAL}


begin {main}
     assign (Statefile, 'A:\state2.dat');
     reset (Statefile);
     while not seekeof (Statefile) do
       begin
         GETDATA (Statefile, state, capital);
         GUESS_CAPITAL (tries, guess);
       end;
     close (Statefile)
end.

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
2 Comments
 
LVL 6

Accepted Solution

by:
My name is Mud earned 20 total points
ID: 2657609
Here's your problem...


if (numb < 10) and (wt < 180) then
  writeln ('Accepted '); <-this semicolon does not belong in here if you're gona make an ELSE statement...
else


if guess = capital then
  writeln ('Nice work.  You got it on try ', tries); <-Same here...
else


If <condition> Then
  <sentence>;

If <condition> Then
  Begin
    <sentence>;
    <sentence>;
    <sentence>   {<- This last sentence before the End can be like this, without semicolon}
  End;

If <condition> Then
  <sentence>
Else
  <sentence>;

If <condition> Then
  Begin
    <sentence>;
    <sentence>
  End
Else
  <sentence>;

If <condition> Then
  <sentence>
Else
  Begin
    <sentence>;
    <sentence>
  End;

If <condition> Then
  Begin
    <sentence>;
    <sentence>
  End
Else
  Begin
    <sentence>;
    <sentence>
  End;


See the path here??? Learn to use the IF-THEN-ELSE and the nested IFs Like:

If <condition1> Then
  If <condition2> Then
    If <condition3> Then
      <sentence>

Will be like:
  If <condition1> And <condition2> And <condition3> Then
    <sentence>


And know how to use it like:
If <condition> Then
  <sentence>
Else If <condition> Then
  <sentence>
Else If <condition> Then
  <sentence>
Else
  <sentence>
0
 
LVL 6

Expert Comment

by:My name is Mud
ID: 2657620
Just think about it, like in real life...

Suppose you're walking in a street, and there's a 10 dollar bill, laying in the street side, what would you do??? pick it up; So...
  If <dollar bill in street side> Then
    <pick it Up>;

But what if there were two bills??? well you pick one, then the other...
  If <dollar bills in street side> Then
    Begin {you have to use it to state the begin of a "Block"}
      <Pick up first bill>;
      <Pick up second bill>
    End;

But what if they were pooped???
  If <dollar bill in street> AND NOT<pooped> Then
    <Pick up bill>
  Else
    <walk away>;

Then what if there were 2 bills, and you really, really need 'em...
  If <dollar bill in street> AND NOT <pooped> Then
    Begin
      <pick up first bill>;
      <pick up second bill>
    End
  Else
    Begin
      <clean first pooped bill>
      <pick up bill>
      <clean second pooped bill>
      <pick up bill>
    End;

Now you could create a procedure to "clean the pooped bill", or something to optimize your code...
0

Featured Post

On Demand Webinar - Networking for the Cloud Era

This webinar discusses:
-Common barriers companies experience when moving to the cloud
-How SD-WAN changes the way we look at networks
-Best practices customers should employ moving forward with cloud migration
-What happens behind the scenes of SteelConnect’s one-click button

Question has a verified solution.

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

If you are a mobile app developer and especially develop hybrid mobile apps then these 4 mistakes you must avoid for hybrid app development to be the more genuine app developer.
A new hacking trick has emerged leveraging your own helpdesk or support ticketing tools as an easy way to distribute malware.
In this video, Percona Solution Engineer Dimitri Vanoverbeke discusses why you want to use at least three nodes in a database cluster. To discuss how Percona Consulting can help with your design and architecture needs for your database and infras…
In this video, Percona Solutions Engineer Barrett Chambers discusses some of the basic syntax differences between MySQL and MongoDB. To learn more check out our webinar on MongoDB administration for MySQL DBA: https://www.percona.com/resources/we…

660 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