Solved

# show capital guessed in four or less tries

Posted on 2000-03-26
239 Views
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
end; {GETDATA}

procedure GUESS_CAPITAL (var tries: integer;
guess: string);

begin{GUESS_CAPITAL}
tries := 0;
repeat
tries := tries + 1;
write ('Give capital of ', state, ' ' );
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
Question by:kazooie21
[X]
###### Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

• Help others & share knowledge
• Earn cash & points
1 Comment

LVL 49

Accepted Solution

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
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, ' ' );
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

Question has a verified solution.

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

Compliance and data security require steps be taken to prevent unauthorized users from copying data.  Here's one method to prevent data theft via USB drives (and writable optical media).
This article is written by John Gates, CISSP. Gates, the SNUG President-Elect, currently holds the position of Manager of Information Systems at Lake Park High School in Roselle, Illinois.
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to fâ€¦
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philosâ€¦
###### Suggested Courses
Course of the Month7 days, 7 hours left to enroll