Created
July 10, 2019 14:32
-
-
Save qutal/bd43e847bd1fd6fe335ad1527d04a413 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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> "; | |
?> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<!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