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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |