Solved

just wanna print!

Posted on 2000-03-27
10
188 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 47

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
 
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
Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

 
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 47

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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

Suggested Solutions

Find out what Office 365 Transport Rules are, how they work and their limitations managing Office 365 signatures.
A Short Story about the Best File Recovery Software – Acronis True Image 2017
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…
This video shows how to remove a single email address from the Outlook 2010 Auto Suggestion memory. NOTE: For Outlook 2016 and 2013 perform the exact same steps. Open a new email: Click the New email button in Outlook. Start typing the address: …

708 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

13 Experts available now in Live!

Get 1:1 Help Now