Hi, so i am trying to create a simple math game using perl.
In the game there are 2 random numbers generated. Then the user has to do the math and type in the answer. If they get it right they plant a crop, if not the plant dies. I cannot get it to update the 'crop planted' or 'crop not planted'. It is like a point system. It starts a 0, then everytime the user gets the correct answer 'crop planted' goes up 1, but if they get it wrong 'crop not planted' goes up 1. It seems to be reading the input as blank before the user even enters the answer, but I'm not sure how to correct it.
Here's the code...
print "Content-type: text/html\n\n";
use CGI qw(:standard);
#@number1=("12" .. "25");
$correctanswer=($number1rand + $number2);
print "$correctanswer <br>";
<form method="post" action="foodaddition.cgi" name="form2">
Crops planted: $cornplanted <br>
<input type="hidden" name="$cornplanted" id="$cornplanted" />
Crops not planted: $cornnotplanted <br>
<input type="hidden" name="$cornnotplanted" id="$cornnotplanted" />
What does this math problem equal? <br>
$number1rand + $number2 = <input type="text" name="response1" id="resp
<input type="hidden" name="response1" id="response1" />
<input type="submit" name="submit" value="Submit" />
if ($response1 eq "$correctanswer")
$cornplanted=($cornplanted + 1);
elsif ($response1 ne "$correctanswer")
$cornnotplanted=($cornnotplanted + 1);
print "not correct!";
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:
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, 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, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.
| & || & |
| < || < |
| > || > |
| [ || [ |
| ] || ] ||