Perform external value calculations ($_GET)

Asked

Viewed 66 times

-1

Good afternoon, I’m new in php, and I’m doing some exercises, but I’m not able to do an exercise that ask to do sum, division, multiplication or subtraction depending on the values entered in $_GET, but using elseif? I leave an image of the exercise, because they are two points, the first part already made, the second I’m not understanding how to do! Print screen dos dois exercicios.

  • Please edit your question by including the code you’ve already developed for question 1 so we can assist you.

  • Just as you send the numbers, will send the operator by url($_GET) and apply the correct operation. ex: if($operacao == '+'){ echo $a + $b;}, remember to treat division by zero.

  • Related/almost duplicate: Calculator in php

1 answer

-1

You can do it this way.

Exercise 1

$num1 = $_GET['num1'];
$num2 = $_GET['num2'];

if(($num1 != null) AND ($num2 != null)){

   $result = $num1 + $num2;
   echo "o resulto da soma dos números é: $result";

}else{
   echo "Os valores não foram informados, por favor tente novamente.";
}

Browser other questions tagged

You are not signed in. Login or sign up in order to post.