PHP Learning Simple Calculator Implementation Code _php tutorial

Source: Internet
Author: User
Copy CodeThe code is as follows:


<title>PHP Implementation Simple Calculator</title>


Single-channel Branch
if (Isset ($_get["sub"]))
{
$num 1=true;//Whether the number 1 is an empty tag
$num 2=true;//Whether the number 2 is an empty tag
$numa =true;//Number 1 is a number
$numb =true;//Number 2 is a bit number
$message = "";
Determines whether the number 1 is empty
if ($_get["NUM1"]== "")
{
$num 1=false;
$message. = "The first number cannot be empty";
}
Determine if the number 1 is a number
if (!is_numeric ($_get["NUM1"))
{
$numa =false;
$message. = "The first number is not a number";
}
Determine if the number 2 is a number
if (!is_numeric ($_get["num2"))
{
$numa =false;
$message. = "The second number is not a number";
}
Determines whether the number 2 is empty
if ($_get["num2"]== "")
{
$num 2=false;
$message. = "The second number cannot be empty";
}
if ($num 1 && $num 2 && $numa && $numb)
{
$sum = 0;
Multi-Channel 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
}
}
}
?>




Calculator





http://www.bkjia.com/PHPjc/323562.html www.bkjia.com true http://www.bkjia.com/PHPjc/323562.html techarticle Copy the code code as follows: HTML head titlephp implementation simple calculator/title meta http-equiv= "Content-type" content= "text/html;charset=gb2312"/head ? PHP//Single channel branch if (Isset ($_get[ ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.