Hi everyone! I'm new here. I've been doing Pascal for a little while, and it's become very interesting to me recently. This program I'm working on at the moment however has confused me. It's a program that is supposed to help you with learning vocabularly. The idea is as follows: The words will be records stored in a binary file, with variables of meaning, english tally, and the position of the record in the file. There are 3 functions. First you can add new words. No problem with that. Second you can correct already added words. Works fine. And third comes the real use of the program. It asks you randomly a chosen number of questions and checks if your answer is correct. The problem is,since it randoms which number to go to, there is a decent possibility for one or two words being asked more than once. I had an idea to solve this: Let's collect the numbers of the already asked words into an array, and keep randoming until the random number isn't in that array. But this just doesn't work. I'm stuck. I don't know what is wrong, the procedure or the function. I'll give the related parts of the code here. Thanks in advance, have a nice day everyone!
Code:
Type szo=record
hun:string;
eng:string;
num:integer; {This variable is only needed for the correction function}
Var
f: file of szo;
ticked:array[1..1000] of integer;
Function is_in_arr(testval,max,arr):boolean;
var count,i:integer;
begin
count:=0;
for i:=1 to max do if testval=arr[i] then inc(count);
if count>0 then is_in_arr:=true else is_in_arr:=false;
end;
Procedure quest(numofquest:integer);
var
ans:string;
posvar,j:integer;
tempw:szo;
begin
reset(f)
for j:=1 to numofquest do
begin
repeat
posvar:=random(filesize(f));
Until is_in_arr(posvar,numofquest,ticked)=false;
ticked[j]:=posvar;
seek(f,posvar);
read(f,tempw);
Writeln('Hungarian: ',tempw.hun);
Write('English: ');
Readln(ans);
If ans=tempw.eng then
writeln('Congratulations!')
else writeln('Wrong! The correct answer is: ',tempw.eng);
end;
Close(f);
menu; {This calls the menu procedure}
end;
{Randomize, and Assign are called in the main program}
Note: When I get really good at this I'm looking forward to try myself out and write a game, but there is a lot to practise yet. Object pascal and SDL are both quite new to me
Bookmarks