2
I have the following code:
print ("Primeiro Valor: ");
$valor1 = <STDIN>;
print ("Segundo Valor: ");
$valor2 = <STDIN>;
print ("Operador: ");
$op = <STDIN>;
if ($op == "+")
{
$total = $valor1 + $valor2;
print ($total);
}
elsif ($op == "-")
{
$total = $valor1 - $valor2;
print ($total);
}
elsif ($op== "*")
{
$total = $valor1 * $valor2;
print ($total);
}
elsif ($op == "/")
{
$total = $valor1 / $valor2;
print ($total);
}
He reads everything correctly but when he enters the if
if the user enters "-"
, "/"
or "*"
he always enters the first condition and makes a sum and wanted to try to understand why.
I understood now what I had done wrong, your explanation helped a lot to understand. My previous programming experience was C# and Python and I have now started Perl with some exercises and I wasn’t really able to solve this, but I understood what was wrong.
– Medium