• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 243
  • Last Modified:

for dbrunton

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
kazooie21
Asked:
kazooie21
  • 2
1 Solution
 
BatalfCommented:
Why don't you kazooie21 and dbrunton try to get your own site in here.
0
 
dbruntonCommented:
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
 
dbruntonCommented:
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

Hire Technology Freelancers with Gigs

Work with 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.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now