#!/usr/bin/perl
use strict;
use warnings;
use Regexp::Common qw /number/;

print "- Semplice Calcolatrice by Kiki -\n\n";
print "Inserisci primo numero:\n";
my $first = <STDIN>;
chomp($first);
while ($first !~ /^$RE{num}{real}$/ and $first !~ /^$RE{num}{int}$/)
{
	print "Non e` un numero\n";
	print "Inserisci un numero:\n";
	$first = <STDIN>;
	chomp($first);
}

print "E ora il secondo:\n";
my $second = <STDIN>;
chomp($second);
while ($second !~ /^$RE{num}{real}$/ and $second !~ /^$RE{num}{int}$/)
{
	print "Non e` un numero\n";
	print "Inserisci un numero:\n";
	$second = <STDIN>;
	chomp($second);
}


print "Ora scegli l'operatore:\n";
my $oper = <STDIN>;
chomp($oper);
  
while ($oper ne '+' and $oper ne '-' and $oper ne '*' and $oper ne '/')
{
	print "Ma che razza di operatore hai scelto\n";
	print "Inserisci un operatore corretto:\n";
	$oper = <STDIN>;
	chomp($oper);
}

if ($oper eq '+')
{
      my $somma = $first + $second;
      print $somma;

} elsif ($oper eq '-')

{
       my $sottrazione = $first - $second;
       print $sottrazione

} elsif ($oper eq '*')

{
      my $molti = $first * $second;
      print $molti;

} elsif ($oper eq '/')

{
      while ($second == 0)
      {
 		print "Scegli un denominatore diverso da 0, se no il prog non funzica\n";
	        $second = <STDIN>;
	        chomp($second);
      }
      my $divi = $first / $second;
      print $divi;
}

