# How to make a quiz program in turbo pascal?

I need to make a quiz with 30 question (15 multiple choice, 15 cloze questions), and have the order of all questions randomized. It also must calculate the result as a percent and display the qeustions answered wrongly with the correct answer. Even just a sample with 3 or 4 example questions would be fine. I can almost do it, but i cant seem to randomize the order, and so that I dont get the same question appearing more than once. Any help would be [b]GREATLY[/b] appreciated.

• I made a very dodgy program for this, but it doesnt stop a question being asked more than once. I know this is a very dodgy way of doing it, but its the only way i can do it(im pretty new to programming).
here it is...

program assessment;

uses wincrt;

type

question = record
count: integer;
end;

var

counter: integer;
questions: array[1..3] of question;
correctscore, incorrectscore: integer;
number: array[1..3] of integer;

procedure Q1;
begin
questions.ask:= 'What is an integer? 1. A fraction 2. A whole number 3. A decimal';
then correctscore := correctscore + 1
else incorrectscore := incorrectscore + 1;
end;

procedure Q2;
begin
questions.ask:= 'What does BNF stand for? 1. Backus-Naur Form 2. Backus-Noir Form 3. Big Naughty Farmer';
then correctscore := correctscore + 1
else incorrectscore := incorrectscore + 1;
end;

procedure Q3;
begin
questions.ask:= 'An example of an object driven programming language is? 1. Pascal 2. C 3. Java';

then correctscore := correctscore + 1
else incorrectscore := incorrectscore + 1;
end;

begin
correctscore:= 0;
incorrectscore:= 0;

randomize;
number:= random(3) + 1;
number:= random(3) + 1;
number:= random(3) + 1;
writeln ('Welcome to the QUIZ, by Jesse');
writeln ('');

if number = 1 then
Q1
else if number = 2 then
Q2
else if number = 3 then
Q3;
if number = 1 then
Q1
else if number = 2 then
Q2
else if number = 3 then
Q3;
if number = 1 then
Q1
else if number = 2 then
Q2
else if number = 3 then
Q3;

writeln ('');
writeln ('');
writeln ('Answers correct = ', (correctscore),' ');
writeln ('Answers incorrect = ', (incorrectscore),' ');
writeln ('');

end.
• [code][color=Blue]{\$apptype console}
{\$type turbo} // <-- turn on TP compability

uses crt;

const n{umber of questions}=5;
q{uestions}:array[1..n] of string=
('Question 1',
'Question 2',
'Question 3',
'Question 4',
'Question 5');
a{nswers}:array[1..n,1..3] of string= // first entry is considered to be the right one
l:array[1..3] of char='ABC'; // hotkeys for answers

procedure swap_(var a,b:word); // a quick way to swap two integers
begin if a=b then exit;a:=a xor b;b:=a xor b;a:=a xor b;end;

var i,j,hits:word;
o{ questions order }:array[1..n] of word; // <-- this allows for max. 65565 of q.'s
oa{ answers order }:array[1..3] of word; // <-- for randomizing the answers, because the good one is stored 1st
t{riggers}:array[1..n] of boolean; // <-- to see which question got bad answer
ch:char;

begin
hits:=0; // <-- number of good answers
fillchar(t,sizeof(t),1); // init triggers with "true" values
randomize; // init random no. generator
for i:=1 to n do o[i]:=i;
for i:=1 to 3 do oa[i]:=i; // initial values
for i:=1 to n*2 do // n*2 swaps to randomize order, for high n values use: sqr(n)/2
swap_(o[random(n)+1],o[random(n)+1]);
i:=1;
{###### main loop ############}

repeat
writeln(#13#10#13#10'Question no. ',i,' of ',n,' Press ',l,',',l,',',l,' for correct answer, Esc to quit'#13#10);
writeln(' ',q[o[i]]); // display question
for j:=1 to 6 do // randomize answers order
swap_(oa[random(3)+1],oa[random(3)+1]);
for j:=1 to 3 do // display answers
writeln(#13#10,' ',l[j],') ',a[o[i],oa[j]]);

repeat
ch:=upcase(readkey); // wait for user input + capitalize
until ((ch=l) or (ch=l) or (ch=l) or (ch=#27)); // only the the hotkeys and Esc can pass here, everything else is ignored
delay(100); // slight delay
while keypressed do readkey; // flush keyboard buffer in case of multiple keypresses

for j:=1 to 3 do // check if user answered right
if ((ch=l[j]) and (oa[j]=1)) then begin
inc(hits); // increase hit number
t[o[i]]:=false; // turn off trigger
end;

inc(i); // go to next question
until ((ch=#27) or (i>n)); // user abort or reached max. number of questions

{############################}
dec(i);
writeln(#13#10#13#10);
if i>> The correct answer is:');
writeln(' ',a[o[j],1],#13#10);
end;
end;