<?

// Ilk sayi

$sayi1 = (double)$_REQUEST['sayi1'];

// Matematiksel Islem

$islem = $_REQUEST['islem'];

// Ikinci Sayi

$sayi2 = (double)$_REQUEST['sayi2'];

// Ileriye donuk bir parametre, hesap makinesine islemi yapmasini

// sonucu ekrana yazdirmasini bildiriyor…

$komut = $_REQUEST['komut'];

// Formu,programin kendisi uzerine GET ile gonderiyoruz.

// Formda gizli bir 'komut' alani var degeri 'islemi_uygula'

// Boylece islemi yapmasi gerektigini anliyor,

$ben = $PHP_SELF;

if ($komut == 'islemi_uygula') {

if ($islem == '+') {

$sonuc = (double)($sayi1 + $sayi2);

}

if ($islem == '-') {

$sonuc = (double)($sayi1 - $sayi2);

}

if ($islem == '*') {

$sonuc = (double)($sayi1 * $sayi2);

}

if ($islem == '/') {

if (0 != $sayi2){

$sonuc = (double)($sayi1 / $sayi2);

} else {

echo "<br>Bolunen sayi sifir olamaz!";

}

}

if ($islem == 'kalan') {

$sonuc = (double)($sayi1 % $sayi2);

}

}

?>

<>

<body>

<?

// Sonuc diye bir degisken varsa ekranda goster yoksa bos gec

if (isset($sonuc)) { echo "Sonuc:".$sonuc; }

?>

<BR>

<!– Formu Goster –>

< action="<? echo $_SERVER['PHP_SELF']; ?>" method="GET">

<input type="hidden" name="komut" value="islemi_uygula">

SAYI1:

<input type="text" name="sayi1">

ISLEM:

<SELECT name="islem">

<option value="+" selected="true">+</option>

<option value="-">-</option>

<option value="*">x</option>

<option value="/">/</option>

<option value="kalan">kalan (%)</option>

</select>

SAYI2:

<input type="text" name="sayi2">

<input type="submit" value="Islemi Gerceklestir">

</>

</body>

</>

kaynak: ordan burdan

Tags: , , , , , , , , , , , ,
Php - Hesap Makinesi (scripti, nasıl, nedir?) konusu
Benzer yazılar:
    Benzer yazı yok