PHP Simple Calculator
This is the use of PHP conditional control statements written, relatively simple, digest ...
<title>PHP Implementation Simple calculator (using branch structure)</title>
";} else if (!is_numeric ($_post["NUM1"])) {$mess. = "The first number must be a number!"
";} if ($_post["num2"] = = "") {$mess. = "The second number cannot be empty!"
";} Else{if (!is_numeric ($_post["num2"])) {$mess. = "The second number must be a number!"
";} else if ($_post["opt"] = = "/" && $_post["num2"] = = 0) {$mess. = "Divisor cannot be 0";}}? >
| ' If (! $mess) {$sum = 0;switch ($_post["opt"]) {case "+": $sum = $_post["NUM1"] + $_post["num2"];break;case "-": $sum = $_post ["NUM1"]-$_post["num2"];break;case "x": $sum = $_post["NUM1"] * $_post["num2"];break;case "/": $sum = $_post["NUM1"]/$_p ost["num2"];break;case "%": $sum = $_post["NUM1"]% $_post["num2"];break;} echo "Result: {$_post[' Num1 '} {$_post[' opt '}} {$_post[' num2 '}} = {$sum}"; }else{echo $mess;} Echo ' |
';}? >