Solved

show capital guessed in four or less tries

Posted on 2000-03-26
1
233 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 48

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

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

There are many Password Managers (PM) out there to choose from. PM's can help with your password habits and routines, but they should not be a crutch you rely on too heavily. I also have an article for company/enterprise PM's.
Some code to ensure data integrity when using macros within Excel. Also included code that helps secure your data within an Excel workbook.
Along with being a a promotional video for my three-day Annielytics Dashboard Seminor, this Micro Tutorial is an intro to Google Analytics API data.
Internet Business Fax to Email Made Easy - With  eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, f…

911 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