Solved

just wanna print!

Posted on 2000-03-27
10
189 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 48

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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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 48

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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

When we talk about DevOps toolchains, I sometimes wonder how many people really get what we’re talking about. I don’t know if it’s just semantics or tone or something else, but sometimes I think it just sounds like buzzword sausage. So it’s always …
Introduction This article is intended for those who are new to PHP error handling (https://www.experts-exchange.com/articles/11769/And-by-the-way-I-am-New-to-PHP.html).  It addresses one of the most common problems that plague beginning PHP develop…
This Micro Tutorial demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Video by: Mark
This lesson goes over how to construct ordered and unordered lists and how to create hyperlinks.

920 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

16 Experts available now in Live!

Get 1:1 Help Now