#!/usr/bin/perl

use CGI;
$object = new CGI;

print $object->header, $object->start_html;

$correct = 0; # added by Adam, is not necessary

$correct = $object->param('correct'); # added by Adam, not noticed by Dopey (Adrian)
# see http://imagecache2.allposters.com/images/pic/ADVG/681~Dopey-Posters.jpg for ref

$answer = $object->param('answer');

$x = int(rand(100)) - 50;
$y = int(rand(100)) - 50;

$num1 = $object->param('num1');
$num2 = $object->param('num2');

if ($answer !~ /^\s*$/) {
  if ($num1 + $num2 == $answer) {
    print "Yes, $num1 + $num2 is indeed equal to $answer <hr>";
    $correct = $correct+1; # added by Adam, correctly
  } else {
    print "No, $num1 + $num2 is actually ", ($num1 + $num2), " and not $answer as you incorrectly indicated.<hr>";
  }
  print "<BR>You have $correct correct answers<hr>"; # added by Adam, correctly
}

print qq{
<form>

  What is $x + $y ? <p>

  Type answer here: <input type="text" name="answer" size=4> then press

  <input type="submit" name="submit" value="Proceed"> to send it.

<input type="hidden" name="num1" value="$x">
<input type="hidden" name="num2" value="$y">
<input type="hidden" name="correct" value="$correct">

</form>}, # for the next four lines credit goes to Adam: good idea!
qq{ <form>
Or press reset <input type=submit value=Reset>
</form>
};


print $object->end_html;