Solved

for dbrunton

Posted on 2000-03-31
3
205 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 47

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 47

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

6 Surprising Benefits of Threat Intelligence

All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

Join & Write a Comment

HOW TO: Upload an ISO image to a VMware datastore for use with VMware vSphere Hypervisor 6.5 (ESXi 6.5) using the vSphere Host Client, and checking its MD5 checksum signature is correct.  It's a good idea to compare checksums, because many installat…
Veeam Backup & Replication has added a new integration – Veeam Backup for Microsoft Office 365.  In this blog, we will discuss how you can benefit from Office 365 email backup with the Veeam’s new product and try to shed some light on the needs and …
Illustrator's Shape Builder tool will let you combine shapes visually and interactively. This video shows the Mac version, but the tool works the same way in Windows. To follow along with this video, you can draw your own shapes or download the file…
This video demonstrates how to create an example email signature rule for a department in a company using CodeTwo Exchange Rules. The signature will be inserted beneath users' latest emails in conversations and will be displayed in users' Sent Items…

707 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

15 Experts available now in Live!

Get 1:1 Help Now