Dear Monks,

I am trying to make an "all-in-one area calculator" for my brother to help him with his homework. I thought it would be an easy task. The problem I have is, when it asks "What kind of shape am I working with?", and I say "rectangle", it starts printing the things it is supposed to print when I type in "square". Note: The code is below. All of the scalars at the top are not needed, I just put them there to refer to.

Oh, and I know I might not have been to clear so if you have questions please ask.

use 5.12.4; use Math::Trig; use strict; ###################################################################### +##### 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); while ($type){ if ($type eq 'square' or '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"; last; }} while ($type){ if ($type eq 'rectangle' or '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=<>; say "ANSWER= $rectangle_area"; last;}} while ($type){ if ($type eq 'paralellogram' or 'Paralellogram'){ say "Okay. I am working with a $type.\n"; say "ENTER BASE"; $paralellogram_base=shift; say "ENTER HEIGHT"; $paralellogram_height= shift; say "ANSWER= $paralellogram_area"; last;}}

perl.j-----A Newbie To Perl

In reply to What is wrong with this code? by perl.j

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.