help with perl, Subroutines, need by Monday night (before 9 pm EST if possible)?

  • Thread starter Thread starter el gizmo magnifico
  • Start date Start date
E

el gizmo magnifico

Guest
ok I have 1 more problem to go but I can't seem to figure it out on what to do. so can anyone help me.

here is the problem
Copy rectangle04.pl to rectangle05.pl. Add code within the subroutine to separately check the values of length and width to be sure they are greater than zero. If either value is zero or less than zero print an informative message and stop the program. All checks should be done in the getArea subroutine.
HERE IS RECTANGLE04.pl

#!/usr/bin/perl -w
#
# ================= Subroutines ===================
#
# --------------------------------------------------
# SUBROUTINE: max
# OBJECTIVE: Return the maximum value of two numbers.
#
# SAMPLE USAGE:
# $maxValue = &max($firstValue,$secondValue) ;
#
# KNOWN BUGS: No error checking.

# --------------------------------------------------
sub max {
if($_[0] > $_[1]) {
$_[0] ; # return first value.
}
else {
$_[1] ; # return second value.
} ;
}
# --------------------------------------------------
# SUBROUTINE: min
# OBJECTIVE: Return the minimum value of two numbers.
#
# SAMPLE USAGE:
# $minValue = &min($firstValue,$secondValue) ;
#
# KNOWN BUGS: No error checking.
# --------------------------------------------------
sub min {
if($_[0] < $_[1]) {
$_[0] ; # return first value.
}
else {
$_[1] ; # return second value.
} ;
}
#--------------------------------------------------
# SUBROUTINE: getArea
# OBJECTIVE: Return the area of a rectangle from the
# two input numbers.
#
# SAMPLE USAGE:
# $area = getArea($length,$width) ;
#
# KNOWN BUGS: No error checking.
# --------------------------------------------------
sub getArea {
my $length = $_[0] ;
my $width = $_[1] ;
my $area = $length * $width ;
return $area ;
}
# ================= main program ===================
print "Enter the first value:" ;
$firstValue = <STDIN> ;
chomp $firstValue ;
print "Enter the second value:" ;
$secondValue = <STDIN> ;
chomp $secondValue ;
$maxValue = &max($firstValue,$secondValue) ;
print "The maximum value is $maxValue\n" ;

$minValue = &min($firstValue,$secondValue) ;
print "The minimum value is $minValue\n" ;

$getArea = &getArea ($firstValue,$secondValue) ;
print "the area is $getArea\n" ;

if you need to know more about what im doing here is the pages

http://cset.stcc.edu/~edbigos/courses/2008fa/cset-111/hw/hw10.pdf
if you need to know more about what im doing here is the pages

http://cset.stcc.edu/~edbigos/courses/2008fa/cset-111/hw/hw10.pdf
 
I can't believe how BAD the other two answers are! Do you guys even know Perl? I've been a professional Perl programmer for OVER TEN YEARS. It's so simple:

if ($length <= 0)
{
print STDERR "Length is less than zero, can not continue";
exit 88;
}

Do the same thing for $width
 
Back
Top