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 :)


In reply to Homework question - passing private variables back and forth between two scrips by linkperl

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.