Solved

How would I modify this program

Posted on 2000-03-30
3
232 Views
Last Modified: 2010-04-16
How would I change this program so it will output BOTH the number of capitals gotten in 1 guess and the number gotten in 4 guesses?

Here it is:

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
      readln (localStatefile, localstate);
      readln (localStatefile, localcapital);
   end; {GETDATA}


procedure GUESS_CAPITAL (var tries: integer;
                         guess: string;
                         var localcorrect_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
         writeln ('Nice work. You got it on try ', tries);
         inc(localcorrect_guess);
      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 (localcorrect_guess: integer);
   begin
     writeln ('You have guessed ' ,localcorrect_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
Comment
Question by:kazooie21
  • 2
3 Comments
 
LVL 47

Expert Comment

by:dbrunton
Comment Utility
Can you give some examples of the output you require because it is not clear enough?   Once you do that the rest is easy.
0
 
LVL 6

Accepted Solution

by:
My name is Mud earned 10 total points
Comment Utility
------------------------ Try this: -----------------------------
var
  wrongguesses: Array[1..4] Of String;
  state: string;
  Capital : string;
  Statefile: text;
  I,tries: integer;
  guess: string;
  correct_guess: integer;

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 localcorrect_guess: integer);
begin{GUESS_CAPITAL}
  tries := 0;
  repeat
    tries := tries + 1;
    write ('Give capital of ', state, ' ' );
    readln (guess);
    wrongguesses[tries]:=guess;
  until (guess = capital) or (tries = 4);
  if guess = capital then
    Begin
      writeln ('Nice work. You got it on try ', tries);
      inc(localcorrect_guess);
    End
  else
    begin{until}
      writeln ('You did not get it in 4 tries or less');
      WriteLn('Your wrong guesses were: ');
      For I:=1 to 4 do
        WriteLn(WrongGuesses[Tries]);
      writeln ('The correct answer is ' , capital)
    end;{until}
end; {GUESS_CAPITAL}

procedure GUESSES (localcorrect_guess: integer);
begin
  writeln ('You have guessed ' ,localcorrect_guess, ' states in 4 or fewer tries ');
end;{GUESSES}

begin {main}
  assign (Statefile, 'C: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
 
LVL 6

Expert Comment

by:My name is Mud
Comment Utility
By The WAY, Kazzoie... REMEMBER THIS IS WRONG

    if guess = capital then
      writeln ('Nice work. You got it on try ', tries);
      inc(localcorrect_guess);
    else
      begin{until}
        writeln ('You did not get it in 4 tries or less');
        writeln ('The correct answer is ' , capital)
      end;{until}

First in the
    if guess = capital then
      writeln ('Nice work. You got it on try ', tries);
      inc(localcorrect_guess);
The first Statement <writeln ('Nice work. You got it on try ', tries);> will only be executed, and in the statement <inc(localcorrect_guess);> you use a semicolon, those TWO statements are more than ONE statement, and when you want to execute more than ONE statement, that is TWO, THREE, ONE MILLION, ETC. You USE a Blocked statement, or whatever the name, like...

    BEGIN
       <First statement>; (* <--- Whatch the semicolon?? *)
       <Second Statement>; (* <--- Whatch the semicolon?? *)
       <...>; (* <--- Whatch the semicolon?? *)
       <One Millionth Statement> (* <-- Now here you use or Not use a semicolon, why 'cos is the END of the statement*)
    END;
0

Featured Post

Find Ransomware Secrets With All-Source Analysis

Ransomware has become a major concern for organizations; its prevalence has grown due to past successes achieved by threat actors. While each ransomware variant is different, we’ve seen some common tactics and trends used among the authors of the malware.

Join & Write a Comment

Marketing can be an uncomfortable undertaking, especially if your material is technology based. Luckily, we’ve compiled some simple and (relatively) painless tips to put an end to your trepidation and start your path to success.
In this step by step tutorial with screenshots, we will show you HOW TO: Enable SSH Remote Access on a VMware vSphere Hypervisor 6.5 (ESXi 6.5). This is important if you need to enable SSH remote access for additional troubleshooting of the ESXi hos…
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
This video discusses moving either the default database or any database to a new volume.

763 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

9 Experts available now in Live!

Get 1:1 Help Now