0
I’m having trouble modifying a code I made in else if
for switch
case
. I’m not getting the code to work, he gets values and operation by $_GET
and does the selected operation:
I leave the code here:
if((!is_numeric($num1) || $num1 == '' || $num1 == '0') && $operator == '/')
echo "ERRO: Numero 1 inserido e' zero";
else if((!is_numeric($num2) || $num2 == '' || $num2 == '0') && $operator == '/')
echo "ERRO: Numero 2 inserido e' zero";
else {
//se a divisao for feita por zero, da mensagem de erro informando que o valor inserido foi zero
if( !empty($operator) ) {
if($operator == '+')
$result = $num1 + $num2;
else if($operator == '-')
$result = $num1 - $num2;
else if($operator == '*')
$result = $num1*$num2;
else
$result = $num1/$num2;
echo "O resultado é: ".$result;
}
}
Show me what you’ve done with
switch
. And tell me what problem you found.– Maniero
I haven’t done much yet, I don’t know how to switch case to the first part of ! is_numeric
– Mario Caeiro
vc need to 'separate' the validation of the input numbers with the choice of operation, the switch will probably be applied only in the choice of operation.
– rray
I’ll try to answer the question, but only with this piece of code
– Maniero