Solved

error in statement

Posted on 2000-03-23
1
1,612 Views
Last Modified: 2006-11-17
I have created a text file with 10 states and their capitals. I need an interactive program that will produce as its final output the number of states for which the user was able to guess the capital in four or less tries.



Here's what I got:

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;
      if tries <= 4 then
        writeln ('You got these states in 4 tries or less: ' , state);
      else
        begin
           writeln ('You didn't get these states: ' , state);
        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.

Everytime I compile this I get "Error in statment" on one of the else in the GUESS_CAPITAL procedure.
0
Comment
Question by:kazooie21
1 Comment
 

Accepted Solution

by:
Carpathia earned 20 total points
Comment Utility
When you do an IF.. THEN.. ELSE
you shouldnt terminate the IF with a semicolon.

So it should be

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;
     

Hope this helps.

0

Featured Post

Free Trending Threat Insights Every Day

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Never store passwords in plain text or just their hash: it seems a no-brainier, but there are still plenty of people doing that. I present the why and how on this subject, offering my own real life solution that you can implement right away, bringin…
This article explains how to prepare an HTML email signature template file containing dynamic placeholders for users' Azure AD data. Furthermore, it explains how to use this file to remotely set up a department-wide email signature policy in Office …
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

771 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

12 Experts available now in Live!

Get 1:1 Help Now