in reply to Re: What is wrong with this code?
in thread What is wrong with this code?
Thank You for the code. I will get back to you on the bugs (if any). The reason I didn't make it too easy to use is because I wanted to make sure the basic parts of the code worked first. I am looking to add more to it (and use some of your tips) but for now, here is my finished code:
Oh, and by the way. I know I didn't make that as simple as it can be. I'm working on that. I just wanted to show you guys some of the fixes.
use 5.14.1; use Math::Trig; ###################################################################### +##### my $square_side= shift; ##SQUARE AREA FORMULA my $square_area= $square_side*2; ###################################################################### +##### my $rectangle_side=shift; ##RECTANGLE AREA FORMULA my $rectangle_side_2=shift; my $rectangle_area = $rectangle_side*$rectangle_side_2; ###################################################################### +##### my $paralellogram_base=shift; ##PARALELLOGRAM AREA FORMULA my $paralellogram_height= shift; my $paralellogram_area=$paralellogram_base*$paralellogram_height; ###################################################################### +##### my $trapezoid_base=shift; ##TRAPEZOID AREA FORMULA my $trapezoid_base_2=shift; my $trapezoid_height=shift; my $trapezoid_area=$trapezoid_height/2*($trapezoid_base*$trapezoid_bas +e_2); ###################################################################### +##### my $circle_radius=shift; ##CIRCLE AREA FORMULA my $pi=pi; my $circle_area=$pi*($circle_radius**2); ###################################################################### +###### my $triangle_base=shift; ##NON-EQUALATERAL TRIANGLE FORMULA my $triangle_height=shift; my $triangle_area=.5*($triangle_base*$triangle_height); ###################################################################### +###### say "I am an area calculator. I can calculate the area of most basic s +hapes (mostly).\n"; say "\nWhat type of shape am I working with?\n"; my $type=<>; chomp ($type); if ($type eq 'square' or $type eq 'Square'){ say "Okay. I am working with a $type.\n"; say "ENTER SIDE LENGTH"; $square_side= <>; my $square_area= $square_side*2; say "ANSWER= $square_area"; } elsif ($type eq 'rectangle' or $type eq 'Rectangle'){ say "Okay. I am working with a $type.\n"; say "ENTER FIRST SIDE LENGTH"; $rectangle_side=<>; say "ENTER SECOND SIDE LENGTH"; $rectangle_side_2=<>; $rectangle_area = $rectangle_side*$rectangle_side_2; say "ANSWER= $rectangle_area";} elsif ($type eq 'paralellogram' or $type eq 'Paralellogram'){ say "Okay. I am working with a $type.\n"; say "ENTER BASE"; $paralellogram_base=<>; say "ENTER HEIGHT"; $paralellogram_height=<>; $paralellogram_area=$paralellogram_base*$paralellogram_height; say "ANSWER= $paralellogram_area"; } elsif ($type eq 'trapezoid' or $type eq 'Trapezoid'){ say "Okay. I am working with a $type.\n"; say "ENTER FIRST BASE"; $trapezoid_base=<>; say "ENTER THE SECOND BASE"; $trapezoid_base_2=<>; say "ENTER HEIGHT"; $trapezoid_height=<>; $trapezoid_area=$trapezoid_height/2*($trapezoid_base*$trapezoi +d_base_2); say "ANSWER= $trapezoid_area"; } elsif ($type eq 'circle' or $type eq 'Circle'){ print "Okay. I am working with a $type. \n"; say "ENTER RADIUS"; $circle_radius=<>; my $c_answer= ($circle_radius**2)*3.14; say "ANSWER= $c_answer"; } elsif ($type eq 'triangle' or $type eq 'Triangle'){ print "Okay. I am working with a $type.\n"; say "\n ENTER BASE"; $triangle_base=<>; say "ENTER HEIGHT"; $triangle_height=<>; $triangle_area=.5*($triangle_base*$triangle_height); say "ANSWER= $triangle_area"; }else{ die "I do not have that shape programmed in to my system (yet).Ple +ase tell my creator to add the function you have attempted to use.\n\ +n\n\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: What is wrong with this code?
by flexvault (Monsignor) on Jul 24, 2011 at 18:54 UTC |