kazooie21
asked on
show capital guessed in four or less tries
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
readln (localStatefile, localstate);
readln (localStatefile, localcapital);
end; {GETDATA}
procedure GUESS_CAPITAL (var tries: integer;
guess: string);
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
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.
var state: string;
capital : string;
Statefile: text;
tries: integer;
guess: 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);
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
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.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.