Solved

show capital guessed in four or less tries

Posted on 2000-03-26
1
232 Views
Last Modified: 2012-05-04
This program needs to output the number of states which the user was able to guess the capital in four or less tries. If I leave it like this, then it doesn't work.  Here it is:

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

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

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


begin {main}
     assign (Statefile, 'A:\state2.dat');
     reset (Statefile);
     while not seekeof (Statefile) do
       begin
         GETDATA (Statefile, state, capital);
         GUESS_CAPITAL (tries, guess);
         GUESSES (tries)
       end;
     close (Statefile)
end.
0
Comment
Question by:kazooie21
1 Comment
 
LVL 47

Accepted Solution

by:
dbrunton earned 5 total points
ID: 2660154
program form2;

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

begin{GUESS_CAPITAL}
  tries := 0;
  repeat
    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(local_correct_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 (local_correct_guess : integer);
begin
    writeln ('You have guessed ', local_correct_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

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Suggested Solutions

Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
A Short Story about the Best File Recovery Software – Acronis True Image 2017
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…

757 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

17 Experts available now in Live!

Get 1:1 Help Now