Link to home
Start Free TrialLog in
Avatar of kazooie21
kazooie21

asked on

error in statement

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.
ASKER CERTIFIED SOLUTION
Avatar of Carpathia
Carpathia

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial