All pastes #81065 Raw Edit

Miscellany

public text v1 · immutable
·published 2006-07-07 02:49 UTC
rendered paste body
#!/usr/bin/perl -w
use strict;

my $area; my $peri; my $side; my $radi; my $leng; my $widt; my $base; my $heig; my $base1; my $base2;

print "Welcome to Formula Calculator Version 1.0!\n";

print "What formula do you wish to calculate? ";
my $form = <STDIN>;
chomp $form;

if ( $form eq "area" or "Area" ) {
	print "What shape do you wish to find the area for:  square, circle, rectangle,\n
	parallelogram, triangle, or trapezoid? "; 
	my $shape = <STDIN>;
	chomp $shape
	if ( $shape eq "square" or "Square" ) {
		print "What is the length of one of the sides? ";
		$side = <STDIN>;
		chomp $side;
		$area = $side ** 2;
		print "The area of the square is equal to ", $area, ".";
	} elsif ( $shape eq "circle" or "Circle" ) {
		print "What is the radius? ";
		$radi = <STDIN>;
		chomp $radi;
		$area = 3.14 * $radi ** 2;
		print "The area of the circle is ", $radi, ".";
	} elsif ( $shape eq "rectangle" or "Rectangle" ) {
		print "What is the length? ";
		$leng = <STDIN>;
		chomp $leng;
		print "What is the width? ";
		$widt = <STDIN>;
		chomp $widt;
		$area = $leng * $widt;
		print "The area of the rectangle is equal to ", $area, ".";
	} elsif ( $shape eq "parallelogram" or "Parallelogram" ) {
		print "What is the base? ";
		$base = <STDIN>;
		chomp $base;
		print "What is the height? ";
		$heig = <STDIN>;
		chomp $heig;
		$area = $base * $heig;
		print "The area of the parallelogram is equal to ", $area, ".";
	} elsif ( $shape eq "triangle" or "Triangle" ) {
		print "What is the base? ";
		$base = <STDIN>;
		chomp $base;
		print "What is the height? ";
		$heig = <STDIN>;
		chomp $heig;
		$area = 0.5 * ( $base * $heig );
		print "The area of the triangle is equal to ", $area, ".";
	} elsif ( $shape eq "trapezoid" or "Trapezoid" ) {
		print "What is the measurement of one of the bases? ";
		$base1 = <STDIN>;
		chomp $base1;
		print "What is the measurement of the other base? ";
		$base2 = <STDIN>;
		chomp $base2;
		print "What is the height? ";
		my $heig = <STDIN>;
		chomp $heig;
		$area = 0.5 * $heig * ( $base1 + $base2 );
		print "The area of teh trapezoid is equal to ", $area, ".";
	} else {
		print "That was not a given choice.";
	}
} elsif ( $form eq "perimeter" or "Perimeter" ) {
	print "What is the length? ";
	my $leng = <STDIN>;
	chomp $leng;
	print "What is the width? ";
	my $widt = <STDIN>;
	chomp $widt;
	my $peri = ( $leng * 2 ) + ( $widt * 2 );
	print "The perimeter is equal to ", $peri, ".";
}