Mathematics Quiz in SCAR
By Dan's The Man
Simple to set-up, run the script and have fun answering those mathematical questions 
Currently supports:- Multiplication
- Division
- Addition
- Subtraction
- Exponent
Sample debug output for 5 questions:
1) Correct! 3 + 3 = 6
2) Wrong... 3 + 5 does not equal 7. 3 + 5 = 8
3) Correct! 3^2 = 9
4) Wrong... 8 / 7 does not equal 0.2. 8 / 7 = 1.14
5) Wrong... 3 + 4 does not equal 8. 3 + 4 = 7
scar Code:
(*
Maths Quiz by Dan's The Man (Mayazcherquoi).
Answer the maths questions provided as quick as possible.
Setup lines 12 to 15 :-), run the script and enjoy!
*)
program QuizMaths;
const
QstLimit = 5; //How Many Questions? NOTE: The more questions, the harder they are.
DifLevel = 5; //Difficulty level? 1 = +; 2 = +-; 3 = +-*; 4 = +-*/;
//Max DifLevel is 10. 5 and above uses to the power. The higher the DifLevel from
//5, the harder it is to calculate the answer if it's to the power.
Timing = True; //Time your results?
var
i, dL, i1, i2, dP, tI: Integer;
Ans: Extended;
s, bs: String;
TIA: TExtendedArray;
//Returns the fractional part of the parametre X.
//e.g: X = 1.2, Result := 0.2.
function Frac(const X: Extended): Extended;
begin
Result := X - Int(X);
end;
//Converts parametre X to D decimal places.
function ToDecPla(X: Extended; D: Integer): Extended;
var
n, bX: Extended;
begin
n := Pow(10, d);
bX := x * n;
Result := (Int(bX) + Int(Frac(bX) * 2)) / n;
end;
var
ra: Extended;
begin
ClearDebug;
SetLength(TIA, QstLimit);
dL := DifLevel;
if(dL > 10) then
dL := 10;
if(dL < 1) then
dL := 1;
for i := 1 to QstLimit do
begin
i1 := (RandomRange(1, i + QstLimit - (Random(3)))) + 1;
i2 := (Random(i + QstLimit)) + 1;
case (Random(dL) + 1) of
1:
begin
bS := (IntToStr(i1)) +
' + ' + (IntToStr(i2));
Ans := i1 + i2;
end;
2:
begin
bS := (IntToStr(i1)) +
' - ' + (IntToStr(i2));
Ans := i1 - i2;
end;
3:
begin
bS := (IntToStr(i1)) +
' * ' + (IntToStr(i2));
Ans := i1 * i2;
end;
4:
begin
if(i1 = 0) then
i1 := 1;
bS := (IntToStr(i1)) +
' / ' + (IntToStr(i2));
Ans := i1 / i2;
end;
5..10:
begin
while (i1 > dL) do
i1 := i1 - dL;
while (i2 > dL) do
i2 := i2 - dL;
bS := (IntToStr(i1)) + '^' +
(IntToStr(i2));
Ans := Round(Pow(i1, i2));
end;
end;
if(Timing) then
TIA[i - 1] := GetSystemTime;
s := Readln(bs);
if(Timing) then
TIA[i - 1] := GetSystemTime - TIA[i - 1];
dP := (Length(s)) - (Pos('.', s));
ra := ToDecPla(StrToFloatDef(s, -1234567890), 2);
if(ToDecPla(Ans, 2) = ra) then
Writeln(IntToStr(i) + ') Correct! ' + bS + ' = ' + FloatToStr(ToDecPla(Ans, 2))) else
if(ra = -1234567890) then
Writeln(IntToStr(i) + ') You didn'#39't even attempt to answer ' + bS + '. The answer would'#39've been ' + FloatToStr(ToDecPla(Ans, 2))) else
Writeln(IntToStr(i) + ') Wrong... ' + bS + ' does not equal ' +
FloatToStr(ra) + '. ' + bS + ' = ' + FloatToStr(ToDecPla(Ans, 2)));
if(Timing) then
Writeln('It took you ' + FloatToStr(TIA[i - 1]) + ' milliseconds to answer that question.');
end;
if(Timing) then
begin
Writeln('Your average time to answer those ' + IntToStr(QstLimit) + ' questions was:');
Writeln(' ' + IntToStr(Round(Average(TIA))) + ' milliseconds.');
end;
end.
Enjoy and post your results