: : Then you need to write to another file, which questions the user has answered. If the user wants to answer a question, first check if that question is already listed. If it is, warn the user. Otherwise ask the question.
: :
: I know how to do it.
: But I have another question
: How can I display the question again after I enter the answer
: and display the answer in the position which I wanted.
: And I still don't know how to prevent the user answer the same question again.
: can u give me example.
: Thx!
:
To display text at the same position you need to use the GotoXY() procedure. It's located in the CRT unit.
Here is a sample code to check if user has already answered the question:
var
f: text;
i: integer;
AlreadyAnswered: boolean;
begin
AlreadyAnswered := false;
Assign(f, 'aa.dat');
Reset(f);
while not eof(f) do
begin
readln(f, i);
AlreadyAnswered := i = QuestionIndex;
if AlreadyAnswered then Break; { If found, break out of the loop }
end;
Close(f);
if not AlreadyAnswered then
begin
{ Ask question }
{ Update Already-Answered File: }
Assign(f, 'aa.dat');
Append(f);
writeln(f, QuestionIndex);
Close(f);
end;
end;
The variable QuestionIndex is an integer indicating, which question the user wishes to answer. Remember to clear the aa.dat file before the game using Rewrite().