Solved

for dbrunton

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

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

Microsoft Office Picture Manager was included in Office 2003, 2007, and 2010, but not in Office 2013. Users had hopes that it would be in Office 2016/Office 365, but it is not. Fortunately, the same zero-cost technique that works to install it with …
Scenario: Your operations manager has discovered an anomaly in your security system. The business will start to suffer within 15 minutes if it is a major IT incident. What should she do? We have 6 recommendations for managing major incidents (https:…
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.
Windows 10 is mostly good. However the one thing that annoys me is how many clicks you have to do to dial a VPN connection. You have to go to settings from the start menu, (2 clicks), Network and Internet (1 click), Click VPN (another click) then fi…

895 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

14 Experts available now in Live!

Get 1:1 Help Now