PHP implementation is simple Calculator //Single-way branch
if(isset($_GET["sub"]))
{
$num1=true;//Whether number 1 is an empty mark
$num2= true;//Whether number 2 is a null mark
$numa=true;//Whether number 1 is a number
$numb=true;//Whether number 2 is a digit
$message="";
//Determine whether number 1 is empty
if($_GET["num1"]=="")
{
$num1=false;
$message.="First one The number cannot be empty";
}
//Determine whether number 1 is a number
if(!is_numeric($_GET["num1"]))
{
$numa=false;
$message.="The first number is not a number";
}
//Determine whether number 2 is a number
if(!is_numeric($_GET["num2"]))
{
$numa=false;
$message.="The second number is not a number";
}
//Determine whether number 2 is empty
if($_GET[" num2"]=="")
{
$num2=false;
$message.="The second number cannot be empty";
}
if($num1 && $ num2 && $numa && $numb)
{
$sum=0;
//Multi-way branch
switch($_GET["ysf"]){
case "+":
$sum=$_GET["num1"]+$_GET["num2"];
break;
case "-":
$sum=$_GET["num1"]-$ _GET["num2"];
break;
case "x":
$sum=$_GET["num1"]*$_GET["num2"];
break;
case "/":
$sum=$_GET["num1"]/$_GET["num2"];
break;
case "%":
$sum=$_GET[" num1"]%$_GET["num2"];
break;
}
}
}
?>