Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

just wanna print!

Posted on 2000-03-27
10
Medium Priority
?
198 Views
Last Modified: 2012-05-04
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.
 

0
Comment
Question by:kazooie21
  • 4
  • 2
  • 2
  • +2
10 Comments
 

Author Comment

by:kazooie21
ID: 2661824
It wasn't 'write default' , it was 'write fault' error.
0
 
LVL 1

Expert Comment

by:guyss
ID: 2662944
you should initialize correct_guess to
0 before EACH call to GUESS_CAPITAL.
0
 
LVL 50

Accepted Solution

by:
dbrunton earned 0 total points
ID: 2663028
correct_guess should NOT be initalized to zero.  

This is the total number of times that the user correctly does a guess on the file.  It is incremented each time a successful guess is done.

Place the following at the top underneath program
uses Printer;


and

writeln (Lst, 'You have guessed ' ,localcorrect_guess, ' states in 4 or fewer tries ');
0
Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

 
LVL 3

Expert Comment

by:vikiing
ID: 2663360
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).
0
 

Author Comment

by:kazooie21
ID: 2671060
This question has a deletion request Pending
0
 
LVL 3

Expert Comment

by:vikiing
ID: 2672839
This question no longer is pending deletion
0
 
LVL 3

Expert Comment

by:vikiing
ID: 2672840
You've received some answers that solved your question, ¿could you please tell us why do you want to delete the question?
0
 
LVL 6

Expert Comment

by:My name is Mud
ID: 2672904
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...
0
 
LVL 50

Expert Comment

by:dbrunton
ID: 2673928
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.
0
 
LVL 3

Expert Comment

by:vikiing
ID: 2675855
I saw the repeated question after I posted mi message. Sorry... :(
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

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

Microsoft's Excel has many features that most people will never need nor take advantage of.  Conditional formatting is one feature that you may find a necessity once you start using it.
Mailbox Corruption is a nightmare every Exchange DBA wishes he never has. Recovering from it can be super-hectic if not entirely futile. And though techniques like the New-MailboxRepairRequest cmdlet have been designed to help with fixing minor corr…
In a question here at Experts Exchange (https://www.experts-exchange.com/questions/29062564/Adobe-acrobat-reader-DC.html), a member asked how to create a signature in Adobe Acrobat Reader DC (the free Reader product, not the paid, full Acrobat produ…
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

971 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