Link to home
Start Free TrialLog in
Avatar of kazooie21
kazooie21

asked on

just wanna print!

I tried putting a lst into the line:

writeln ('You have guessed ' ,localcorrect_guess, ' states in 4 or fewer tries ');

When I run the program I get 'write default error'.

Here's the rest:

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

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;
                         var localcorrect_guess: integer);

   begin{GUESS_CAPITAL}

     repeat
       tries := 0;
       tries := tries + 1;
       write ('Give capital of ', state, ' ' );
       readln (guess)
     until (guess = capital) or (tries = 4);
      if guess = capital then
         begin
           writeln ('Nice work.  You got it on try ', tries);
           inc(localcorrect_guess)
         end
      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}

procedure GUESSES (localcorrect_guess: integer);
   begin
     writeln ('You have guessed ' ,localcorrect_guess, ' states in 4 or fewer tries ');
   end;{GUESSES}


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

Avatar of kazooie21
kazooie21

ASKER

It wasn't 'write default' , it was 'write fault' error.
you should initialize correct_guess to
0 before EACH call to GUESS_CAPITAL.
ASKER CERTIFIED SOLUTION
Avatar of dbrunton
dbrunton
Flag of New Zealand image

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
This code block has a problem:
     repeat
       tries := 0;
       tries := tries + 1;
         . . .
     until (guess = capital) or (tries = 4);

As Tries is intialized to 0 INTO the Repeat block, it never reaches the value 4 (not even 2, 'cause your code is the same than to say "tries := 1" at EACH turn).

Change that to

     tries := 0;
     repeat
       Inc(tries);

("Inc" procedure is the simplest way to increment a variable in 1).
This question has a deletion request Pending
This question no longer is pending deletion
You've received some answers that solved your question, ¿could you please tell us why do you want to delete the question?
Oh yeah Kazooie, guess you didn't knew, but it's like, you broke it, you pay it... the man gave you some info, even thought this is a 0 point question, if you accept it with an "A" grade, it will gave vikiing 4 points, not yours of course...
You will actually find this question is posted twice by kazooie under different  titles.  kazooie had two questions running at the same time.  EE went down and he reposted those two under the new titles.

While answering these with comments I was putting them in two different places so the code and comments/answers went all over the place.

As for the block

tries := 0;
repeat
tries := tries + 1;

This is in one of the sample codes I gave to kazooie elsewhere.  If you look in previously answered questions you will find it.  And yes he has paid me for the answers.
I saw the repeated question after I posted mi message. Sorry... :(