Skip to content

Instantly share code, notes, and snippets.

@qutal
Created July 10, 2019 14:32
Show Gist options
  • Save qutal/bd43e847bd1fd6fe335ad1527d04a413 to your computer and use it in GitHub Desktop.
Save qutal/bd43e847bd1fd6fe335ad1527d04a413 to your computer and use it in GitHub Desktop.
<?php
$c1=$_POST["firstCount"];$c2=$_POST["secondCount"];$s=$_POST["sign"];
$res;
if(ctype_digit($c1) && ctype_digit($c2)){
switch ($s) {
case '+':
$res=$c1+$c2;
break;
case '-':
$res=$c1-$c2;
break;
case '*':
$res=$c1*$c2;
break;
case '/':
if($c2!=0){
$res=$c1/$c2;
}else{
$res='Деление на нуль';
}
break;
default:
$res='Неверный ввод знака';
break;
}
}else{
$res="Неверный ввод чисел";
}
echo "Ответ: $res <br> <a href='http://calc/'>Назад</a> ";
?>
<!DOCTYPE html>
<html>
<head>
<title>Калькулятор</title>
</head>
<body>
<form name="Калькулятор" action="calculator.php" method="post">
<label>Первое число</label>
<input type="text" name="firstCount" placeholder="Первое число"> <br>
<label>Второе число</label>
<input type="text" name="secondCount" placeholder="Второе число"> <br>
<label>Знак</label>
<input type="text" name="sign" placeholder="Знак"> <br>
<input type="submit" name="done" value="Готово">
</form>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment