Solved

just wanna print!

Posted on 2000-03-27
10
192 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
Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

 
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 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

Gigs: Get Your Project Delivered by an Expert

Select from freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely and get projects done right.

Question has a verified solution.

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

FAQ pages provide a simple way for you to supply and for customers to find answers to the most common questions about your company. Here are six reasons why your company website should have a FAQ page
There’s a good reason for why it’s called a homepage – it closely resembles that of a physical house and the only real difference is that it’s online. Your website’s homepage is where people come to visit you. It’s the family room of your website wh…
This video shows how to use Hyena, from SystemTools Software, to bulk import 100 user accounts from an external text file. View in 1080p for best video quality.
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

786 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