I have very recently taken up programming, and was told that I should learn Perl first. SO I download the Perl Interpreter and start working on a textfile while reading some of the tutorials on the side. After about 3 hours of doing this, I come up with the following code:
- Code: Select all
#!D:\Perl\bin\perl #This is because I use Windows.
use warnings;
BEGIN {
open STDERR, ">>", "error.txt";
}
$x = 1 * 81;
$x /= 9;
print "Welcome to the Math Challenge!\nType your name to continue.\n\n";
$name0 = <>;
print "\nWhat is 81/9?\n\n";
$name1 = <>;
if ($name1 == $x) {
print "That is correct, the answer is $x\n\n\n";
}
else {
print "That is wrong, the answer is $x\n";
print "You FAIL!";
}
if ($x < 0) {
print "x can not be zero\n";
}
if ($name1 == $x) {
print "What is 2*2?\n\n";
}
$y = 2 * 2;
$name2 = <>;
if ($name2 == $y) {
print "That is correct, the answer is $y\n\n\n";
}
else {
print "That is wrong, the answer is $y\n";
print "You FAIL!";
}
if ($name2 == $y) {
print "What is 25*3?\n\n";
}
$z = 25 * 3;
$name3 = <>;
if ($name3 == $z) {
print "That is correct, the answer is $z\n\n\n";
}
else {
print "That is wrong, the answer is $z\n";
print "You FAIL!";
}
if ($name3 == $z) {
print "What is 35*2?\n\n";
}
$xx = 35 * 2;
$name4 = <>;
if ($name4 == $xx) {
print "That is correct, the answer is $xx\n\n\n";
}
else {
print "That is wrong, the answer is $xx\n";
print "You FAIL!";
}
if ($name4 == $xx) {
print "Congratulations, $name0!! You Win! \nPress Enter to close window.";
}
$placeholder = <>;
As you see it's very long, and probably not very good, however, it works!! Open in Perl and see for yourself. Anyway, I'm posting it here because I want to improve and learn form experienced programmers. I saw a post about bumming down the lines in the code, so I figured someone might want to try it with this one. I know there are probably many strings and modules that makes the whole thing shorter, but this is my first attempt.
Also, please refrain from stuff like "OMG!! THAT F*ckin SUCKS!!" It's my first day of programming... be patient!


