Random Code

Perl Assignment #2 - Formatted Mutiplication!

#!/usr/bin/perl

print “\n”;
print “################################################\n”;
print “##                                                                                                 ##\n”;
print “##       Multiplication by                                                                    ##\n”;
print “##                 By Brett Lee-Price                                                       ##\n”;
print “##                                                                                                 ##\n”;
print “##            The following should present an aligned                             ##\n”;
print “##             Multiplication table. Well hopefully…                                  ##\n”;
print “##                                                                                                 ##\n”;
print “################################################\n”;

print “\n”;
print “\n”;

for ( $a = 1; $a < 13; $a++ ) #Initial Multiplication of * x Range 1-12.
{
for ( $b = 6; $b < 11; $b++ ) #Range of 6-10 to times against above range.
{
printf "| %2d * %2d=%3d ", $b, $a, $a*$b ; #Formatting
}
print "\n";

}
print "\n";
print "\n";

The PERL file is located here. Again, formatting looks shocking here.

PERL - Random Number Game - TAFE Assignment #1!

#!/usr/bin/perl

print ”
“;
print “################################################
“;
print “## ##
“;
print “## Welcome to the Numbers Game ##
“;
print “## By Brett Lee-Price ##
“;
print “## ##
“;
print “## Rules: Enter 3 Numbers between 0 and 999, ##
“;
print “## The first Answer will be the ultimate ##
“;
print “## Answer as well! No matter which numbers ##
“;
print “## you enter, it's guaranteed! ##
“;
print “## ##
“;
print “################################################
“;

print ”
“;
print “Please enter Number One: “;
$Input[0] = ; # Input one
$Number[0] = $Input[0] + 1998; #Number one being calculated.
while ($Input[0] <=0 || $Input[0] >= 1000) #While Statement for Number One
{
print “An Invalid Number was entered. Please Re-enter Number One: “;
chomp ($Input[0] =);
$Number[0] = $Input[0] + 1998;
$count = $count + 1;
if($count == 4) {
print ”
“;
print “Too many invalid attempts! Terminating Program.”;
print ”
“;
exit;
}
}
print “The Ultimate Answer will be: ${Number[0]}.”; #Ultimate Answer
print ”
“;

print “Please enter Number Two: “;
$Input[1] = ; #Input Two
$Number[1] = 999 - $Input[1]; #Number two being calculated.
$Final[0] = $Input[0] + $Input[1] + $Number[1]; #Part One of Final being worked out with Input One, Two And Answer of Two.
while ($Input[1] <=0 || $Input[1] >= 1000) #While Statement for Number two
{
print “An Invalid Number was entered. Please Re-enter Number Two: “;
chomp ($Input[1] =);
$Number[1] = 999 - $Input[1];
$Final[0] = $Input[0] + $Input[1] + $Number[1];
$count = $count + 1;
if($count == 4) {
print ”
“;
print “Too many invalid attempts! Terminating Program.”;
print ”
“;
exit;
}
}
print “Second answer is: ${Number[1]}.”; #Answer Two
print ”
“;

print “Please enter Number Three: “;
$Input[2] = ; #Input Three
$Number[2] = 999 - $Input[2]; #Number Three being calculated.
$Final[1] = $Input[2] + $Number[2]; #Part Two of Final being worked out with Input Three and Answer Three.
while ($Input[2] <=0 || $Input[2] >= 1000) #While Statement for Number Three
{
print “An Invalid Number was entered. Please Re-enter Number Three: “;
chomp ($Input[2] =);
$Number[2] = 999 - $Input[2];
$Final[1] = $Input[2] + $Number[2];
$count = $count + 1;
if($count == 4) {
print ”
“;
print “Too many invalid attempts! Terminating Program.”;
print ”
“;
exit;
}
}
print “Third answer is: ${Number[2]}.”; #Answer Three
print ”
“;
$Ultimate = $Final[0] + $Final[1]; #Ultimate Answer being calculated.
print ”
“;
print “The Ultimate Answer is: ${Ultimate}.
“; #Ultimate Answer is displayed.
print ”
“;
print “Add every number asides from the first answer!
“;
print “See? Magic!
“;
print ”
“;
print ”
“;

Edit: Looks somewhat ugly here due to the formatting, etc. I've included a better looking and working version here!