Okay it's getting really close, i got the code to update the 'crops planted' and the 'crops not planted'... but for some reason even though i am creating fill-out forms in the CGI.pm documentation, it is still reading the answer for the math problem ($num1 + $num2) before i get a chance to put in the input...so basically i type in a number and until the addition equals that number there is no output, any advice? thanks, and here's the updated code

#!/usr/bin/perl use CGI qw(:standard); $num1=int(rand(20)); $num2=int(rand(12)); print header; print start_html('A Simple Example'), h1('A Simple Example'), start_form, "What's your name? ",textfield('name'), p, "What is $num1 + $num2? ", textfield('addition'), p, "What's the combination?", p, checkbox_group(-name=>'words', -values=>['eenie','meenie','minie','moe'], -defaults=>['eenie','minie']), p, "What's your favorite color? ", popup_menu(-name=>'color', -values=>['red','green','blue','chartreuse']), p, submit, end_form, hr; $correctanswer=($num1 + $num2); $cropsplanted=0; $cropsnotplanted=0; if ((param() and param('addition') == "$correctanswer")) { $cropsplanted=($cropsplanted + 1); $cropsnotplanted=($cropsnotplanted + 0); print "Correct answer: $correctanswer", p, "Crops planted: $cropsplanted", p, "Crops not planted: $cropsnotplanted", p, "Your name is",em(param('name')), p, "Your answer to the math problem is ", em(param('addition')), p, "The keywords are: ",em(join(", ",param('words'))), p, "Your favorite color is ",em(param('color')), } if ((param() and param('addition') != "$correctanswer")) { $cropsplanted=($cropsplanted + 0); $cropsnotplanted=($cropsnotplanted + 1); print "Correct answer: $correctanswer", p, "Crops planted: $cropsplanted", p, "Crops not planted: $cropsnotplanted", p, "Your name is",em(param('name')), p, "Your answer to the math problem is ", em(param('addition')), p, "The keywords are: ",em(join(", ",param('words'))), p, "Your favorite color is ",em(param('color')), }

In reply to Re^2: having trouble with simple math game by Anonymous Monk
in thread having trouble with simple math game by mynameisG

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.