Acesta este partea de HTML dar are inclus si un mic script javascript:
Cod: Selectaţi tot
<html>
<head>
<title>calculator</title>
<link rel="stylesheet" type="text/css" href="css.css"></link>
</head>
<body>
<center>
<div style="top:30px; left:550px; background-color:Aquamarine; border-radius:10px; padding:30px 30px 10px 30px; width:px; position:absolute;">
/// aici vine pus scriptul php pt a afisa rezultatul deasupra liniei de jos
<hr color='#ffffff'>
<form action="calculator.php" method="POST"><br />
<input type="text" name="unu" size="5"/>
<select name="semn1">
<option value=''></option>
<option value="5">+</option>
<option value="10">-</option>
<option value="15">x</option>
<option value="20">:</option>
</select>
<input type='text' name='doi' size='5'/>
<font id='par'></font>
//acesta este javascript-ul cand se apasa pe buton apare casuta pt al treilea numar
<script>
function apasarebuton()
{
document.getElementById("par").innerHTML="<select name='semn2'><option value=''></option><option value='100'>+</option><option value='130'>-</option><option value='160'>x</option><option value='190'>:</option></select> <input type='text' name='trei' size='5'/><br />";
}
</script>
<input type="submit" name='egal' value="Egal"/>
<input id='par' type="button" onclick="apasarebuton()"value='+++'/><br />
</form>
</div>
</center>
</body>
</html>
Cod: Selectaţi tot
<?php
//aici am preluat datele din formulare
@$unu = $_POST['unu'];
@$doi = $_POST['doi'];
@$trei = $_POST['trei'];
@$semn1 = $_POST['semn1'];
@$semn2 = $_POST['semn2'];
/*operatorilor artimetici le-am dat ca si valoare numere iar aici
am creat o variabila caruia i-am dat ca valoare suma dintre cele
dou variabile pt a o putea folosi ca si valoare pt instructiunea case*/
$iesire = $semn1 + $semn2;
//aici am realizat toate operatiile posibile cu doua sau trei numere
$a = $unu + $doi;
$aa = $a + $trei;
$as = $a - $trei;
$ain = $a * $trei;
@$aim = $a / $trei;
$s = $unu - $doi;
$ss = $s - $trei;
$sa = $s + $trei;
$sin = $s * $trei;
@$sim = $s / $trei;
$in = $unu * $doi;
$inin = $in * $trei;
$ina = $in + $trei;
$ins = $in - $trei;
@$inim = $in / $trei;
@$im = $unu / $doi;
@$imim = $im / $trei;
$ima = $im + $trei;
$ims = $im - $trei;
$imin = $im * $trei;
// 5, 10, 15, 20, ... 100, 130, 160, 190
//aici este instructiunea switch care arata rezultatul, am incercat
ci if dar n-am reusit
switch(isset($_POST['egal']))
{
case($iesire == 111):
echo "<marquee behavior='slide' height='40' scrolldelay='100' direction='up'><font id='paragraf'><b>Salutare!!</b></font></marquee>";
break;
case($iesire == 5):
echo "<marquee behavior='slide' height='35' scrolldelay='100' direction='up'><font id='paragraf'><b>$unu + $doi = $a</b></font></marquee>";
break;
case($iesire == 10):
echo "<marquee behavior='slide' height='35' scrolldelay='100' direction='up'><font id='paragraf'><b>$unu - $doi = $s</b></font></marquee>";
break;
case($iesire == 15):
echo "<marquee behavior='slide' height='35' scrolldelay='100' direction='up'><font id='paragraf'><b>$unu . $doi = $in</b></font></marquee>";
break;
case($iesire == 20):
echo "<marquee behavior='slide' height='35' scrolldelay='100' direction='up'><font id='paragraf'><b>$unu : $doi = $im</b></font></marquee>";
break;
case($iesire == 105):
echo "<marquee behavior='slide' height='35' scrolldelay='100' direction='up'><font id='paragraf'><b>$unu + $doi + $trei = $aa</b></font></marquee>";
break;
case($iesire == 135):
echo "<marquee behavior='slide' height='35' scrolldelay='100' direction='up'><font id='paragraf'><b>$unu + $doi - $trei = $as</b></font></marquee>";
break;
case($iesire == 165):
echo "<marquee behavior='slide' height='35' scrolldelay='100' direction='up'><font id='paragraf'><b>$unu + $doi . $trei = $ain</b></font></marquee>";
break;
case($iesire == 195):
echo "<marquee behavior='slide' height='35' scrolldelay='100' direction='up'><font id='paragraf'><b>$unu + $doi : $trei = $aim</b></font></marquee>";
break;
case($iesire == 140): //
echo "<marquee behavior='slide' height='35' scrolldelay='100' direction='up'><font id='paragraf'><b>$unu - $doi - $trei = $ss</b></font></marquee>";
break;
case($iesire == 110):
echo "<marquee behavior='slide' height='35' scrolldelay='100' direction='up'><font id='paragraf'><b>$unu - $doi + $trei = $sa</b></font></marquee>";
break;
case($iesire == 170):
echo "<marquee behavior='slide' height='35' scrolldelay='100' direction='up'><font id='paragraf'><b>$unu - $doi . $trei = $sin</b></font></marquee>";
break;
case($iesire == 200):
echo "<marquee behavior='slide' height='35' scrolldelay='100' direction='up'><font id='paragraf'><b>$unu - $doi : $trei = $sim</b></font></marquee>";
break;
case($iesire == 175): //
echo "<marquee behavior='slide' height='35' scrolldelay='100' direction='up'><font id='paragraf'><b>$unu . $doi . $trei = $inin</b></font></marquee>";
break;
case($iesire == 115):
echo "<marquee behavior='slide' height='35' scrolldelay='100' direction='up'><font id='paragraf'><b>$unu . $doi + $trei = $ina</b></font></marquee>";
break;
case($iesire == 145):
echo "<marquee behavior='slide' height='35' scrolldelay='100' direction='up'><font id='paragraf'><b>$unu . $doi - $trei = $ins</b></font></marquee>";
break;
case($iesire == 205):
echo "<marquee behavior='slide' height='35' scrolldelay='100' direction='up'><font id='paragraf'><b>$unu . $doi : $trei = $inim</b></font></marquee>";
break;
case($iesire == 210): //
echo "<marquee behavior='slide' height='35' scrolldelay='100' direction='up'><font id='paragraf'><b>$unu : $doi : $trei = $imim</b></font></marquee>";
break;
case($iesire == 120):
echo "<marquee behavior='slide' height='35' scrolldelay='100' direction='up'><font id='paragraf'><b>$unu : $doi + $trei = $ima</b></font></marquee>";
break;
case($iesire == 150):
echo "<marquee behavior='slide' height='35' scrolldelay='100' direction='up'><font id='paragraf'><b>$unu : $doi - $trei = $ims</b></font></marquee>";
break;
case($iesire == 180):
echo "<marquee behavior='slide' height='35' scrolldelay='100' direction='up'><font id='paragraf'><b>$unu : $doi . $trei = $imin</b></font></marquee>";
break;
default:
echo "<marquee behavior='slide' height='50' scrolldelay='100' direction='up'><font id='paragraf'><b><i>Hey...incearca sa alegi semnul corespunzator<br />pentru a efectua operatia dorita!!</i></b></font></marquee>";
}
?>