#!/usr/bin/perl
############################################################################
#Program by Mark, also (C) of him too, so don't steal it! #
############################################################################
$Retry = "Y";
print "Hello, and welcome to calculator! This version, 1.0 can handle Multiplication,
Addition, Subtraction, powers, and Division. To exit, type control+C. Improvments are in the works,
so please keep posted!
Thank you for using my software!\n";
while ($Retry eq "Y")
{
$Retry = "N";
print "What problem would you like solved?\n";
$MasterInput =
chomp $MasterInput;
if ($MasterInput =~ /(\d+)([\*\+\^\/\-])(\d+)/)
{
$Input1=$1;
$Operation=$2;
$Input2=$3;
}
else
{
print "Please try the form number-operation-number (6*7)\n";
$Retry = "Y";
}
if ($Operation eq "*")
{
&multiply("$Input1", "$Input2");
}
elsif ($Operation eq "/")
{
÷("$Input1", "$Input2");
}
elsif ($Operation eq "+")
{
&add("$Input1", "$Input2");
}
elsif ($Operation eq "-")
{
&subtract("$Input1", "$Input2");
}
elsif ($Operation eq "^")
{
&power("$Input1", "$Input2");
}
}
sub multiply
{
$Output = $_[0] * $_[1];
print "The answer is $Output\n";
}
sub divide
{
$Output = $_[0] / $_[1];
print "The answer is $Output\n";
}
sub add
{
$Output = $_[0] + $_[1];
print "The answer is $Output\n";
}
sub subtract
{
$Output = $_[0] - $_[1];
print "The answer is $Output\n";
}
sub power
{
$Output = $_[0] ** $_[1];
print "The answer is $Output\n";
}
No comments:
Post a Comment