Solved

for dbrunton

Posted on 2000-03-31
3
215 Views
Last Modified: 2010-04-16
In reference to http://www.experts-exchange.com/jsp/qShow.jsp?ta=pascal&qid=10320474 

I want the output to say something like
writeln(Great! You got these states in 1 try: ', states)

For the other part I believe I can use what I already got.
0
Comment
Question by:kazooie21
  • 2
3 Comments
 
LVL 32

Expert Comment

by:Batalf
ID: 2675731
Why don't you kazooie21 and dbrunton try to get your own site in here.
0
 
LVL 48

Expert Comment

by:dbrunton
ID: 2677345
This should do it.  Creates another file that puts the states into it.


program form2;

var
  state : string;
  capital : string;
  Statefile : text;
  States : text;
  tries : integer;
  guess : string;
  correct_guess : integer;
  correct_state : 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; 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);
      if tries = 1 then
        writeln(States, 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);
  assign(States, 'a:\state3.dat');
  rewrite(States);
  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);
  close(States);
  reset(States);
  writeln('Great! You got these states in 1 try:');
  while not eof(States) do
    begin
     readln(States, correct_state);
     writeln(correct_state);
    end;
  close(States);
end.
0
 
LVL 48

Accepted Solution

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

var
  state : string;
  capital : string;
  Statefile : text;
  States : text;
  tries : integer;
  guess : string;
  correct_guess : integer;
  correct_state : 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; 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);
      if tries = 1 then
        writeln(States, 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);
  assign(States, 'a:\state3.dat');
  rewrite(States);
  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);
  close(States);
  reset(States);
  writeln('Great! You got these states in 1 try:');
  while not eof(States) do
    begin
     readln(States, correct_state);
     writeln(correct_state);
    end;
   close(States);
end.
0

Featured Post

NAS Cloud Backup Strategies

This article explains backup scenarios when using network storage. We review the so-called “3-2-1 strategy” and summarize the methods you can use to send NAS data to the cloud

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
help with delphi code 6 480
Extract text from webbrowser 5 1,394
indy Tidtcpserver best  way to brodcast message to multiable clients 1 157
find a node in VST 2 69
When you have clients or friends from around the world, it becomes a challenge to arrange a meeting or effectively manage your time. This is where Outlook's capability to show 2 time zones in one calendar comes in handy.
Read about the importance of offline branding in the digital age.
This video shows how to quickly and easily add an email signature for all users on Exchange 2016. The resulting signature is applied on a server level by Exchange Online. The email signature template has been downloaded from: www.mail-signatures…

831 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