예제 #1
0
파일: calc.php 프로젝트: EvgeniUPS/project
        case '-':
            return $a - $b;
            break;
        case '*':
            return $a * $b;
            break;
        case '/':
            if ($b == 0) {
                echo ' На ноль делить нельзя';
            } else {
                return $a / $b;
            }
            break;
        default:
            echo "Что-то вы не то ввели. Попробуйте заново.";
            break;
    }
}
if (isset($_POST['a']) && isset($_POST['b'])) {
    include 'calc_form.php';
    $a = $_POST['a'];
    $b = $_POST['b'];
    $c = $_POST['oper'];
    echo math_operations($a, $b, $c);
} else {
    include 'calc_form.php';
}
?>
</body>
</html>
예제 #2
0
파일: index.php 프로젝트: EvgeniUPS/project
	<meta charset="UTF-8">
	<title>Калькулятор</title>
</head>
<body>
<form action="index.php" method="post" autocomplete = "on">
	<fieldset>
	<legend>Калькулятор</legend>
		<input type="text" name="a" value="<?php 
echo "{$a}";
?>
 ">
		<input type="text" name="b" value="<?php 
echo "{$b}";
?>
 ">
		=
		<?php 
echo '<b>' . math_operations($a, $b, $c) . '</b>';
?>
		<br>
		<button name="oper" value="+" class="btn btn-success">+</button>
		<button name="oper" value="-" class="btn btn-info">-</button>
		<button name="oper" value="*" class="btn btn-warning">*</button>
		<button name="oper" value="/" class="btn btn-danger">/</button>

	</fieldset>
</form> 

</body>
</html>