This is a homework question. Had to write two scripts for homework. The first script presents a random math question that the user answers. The second scripts tells you the correct answer, if your answer is correct or incorrect, how many questions have been asked and answered correctly and the percent corrected. You can also click on two links to do another question or clear the counters and start again. Teacher wants the fields hidden between the two scripts and we cannot use a file. Successfully used a form to pass data from script 1 to script 2 and I'm able to pass variables at the end of the URL's from Script 2 to 1 but not hidden. Tired a form in script 2 but don't know how to suppress the boxes that appear. Here's script 1:
#! /usr/bin/perl -wT
use CGI qw(:standard);
use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
use strict;
# generate the begining of the web page.
+
my $title = "CSGA 5030 Project 3: Arithmetic Drilling";
print header, "\n";
print start_html($title), "\n";
print h1($title), "\n";
#print <<EndHTML;
+
+
my @ops = ("*", "/", "+", "-", "%");
my $c;
my $a = int (rand(100));
my $b = int (rand(100));
my $op = $ops[int(rand(@ops))];
# make sure zero is not used for div ops
+
+
if ($op == "/" || "%") {
while ($b == 0 || $a == 0){
$b = int (rand(100));
$a = int (rand(100));
}
};
eval '$c=$a' . $op . '$b';
my $roundc = int ($c);
my $tqa;
my $aca;
# check to see if param has values else set counters to zero
+
+
if (param()) {
$tqa = param("totalQuestions");
$aca = param("answeredCorrectly");
} else {
$tqa = 0;
$aca = 0;
}
print <<EndHTML;
<form action="answer" method="post">
<th>$a $op $b =</th>
<input type="hidden" name="question" value="$a $op $b">
<input type="text" size="4" name="proposedAnswer">
<input type="hidden" name="trueAnswer" value="$roundc">
<input type="hidden" name="totalQuestions" value="$tqa">
<input type="hidden" name="answeredCorrectly" value="$aca">
<input type="submit" value="Check answer!">
<input type="reset" value="Clear">
</form>
EndHTML
Script 2:
#! /usr/bin/perl -wT
use CGI qw(:standard);
use CGI::Carp qw(warningsToBrowser fatalsToBrowser);
use strict;
# generate the begining of the web page.
+
+
my $title = "CSGA 5030 Project 3: Arithmetic Drilling";
my $qweb = "http://www.dsm.fordham.edu/~sheehan/cgi-bin/netwebprog-gra
+d/proj3/question";
print header, "\n";
print start_html($title), "\n";
print h1($title), "\n";
my $question = param("question");
my $correctanswer = param("trueAnswer");
my $proposedans = param("proposedAnswer");
my $tq = param("totalQuestions");
my $ac = param("answeredCorrectly");
print "Question: $question\n";
print "Your answer: $proposedans\n";
print "True answer: $correctanswer\n";
print "";
++$tq; # increment total number of questions asked
if ($proposedans != $correctanswer){
print "<b>Incorrect!</b>\n";
}else {
print "<b>Correct!</b>\n";
++$ac;
}
my $percent = int(($ac/$tq)*100);
print "";
print qq(<p>Score so far: $ac out of $tq ($percent percent) <p>\n);
print qq(<a HREF="$qweb?totalQuestions=$tq&answeredCorrectly=$ac">Try
+another problem</a>\n);
print "\n";
print qq(<a HREF="$qweb?"input type = hidden"
totalQuestions=0&answeredCorrectly=0">Start over with a clean slate</a
+>\n);
Any advice would be greatly appreciated.
GrandFather changed \code tags to /code tags :)