Certainly.

Each time an answer is given, see if it's right, then increment a counter. At the end, you'll have the number of right answers. The code below reads very much like that sentence:

# The code has already asked a question at this point # ("What is the answer to Life, the Universe, and Everything"). # The user has put in his/her answer. # The program has stored it in a scalar, $answer. if ($answer == 42) { $rightanswers++; } # Put that sort of logic in your question/answer loop, # then you can end with something like this: if ($rightanswers == 25) { print "You got all of the questions right! You win!\n"; } elsif ($rightanswers > 20) { print "You got almost all of the questions right. Not bad!\n"; } elsif ($rightanswers > 10) { print "You could've done better...\n"; } elsif ($rightanswers > 1) { print "You did quite poorly...\n"; } else { print "Were you even reading the questions...?\n"; }

In reply to Re: Re: Re: Logical Operators by myocom
in thread Logical Operators by Zombie

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.