Selasa, 03 September 2013

Kodingan Kalkulator

Share it Please
Saya ingin memposting Kodingan Kalkulator melalui php

Body Kalkulator
<html>
<head>
 <title>KALKULATOR</title>
 <H1><b>Masukan Nilai</b></h1>
</head>
<body>
<form method="post" action="prosespilihkalkulator.php">
<label>Input Nilai</label>
<input type="text" name="txtNilai1">
<select name="op">
 <option values="+">+</option>
 <option values="-">-</option>
 <option values="*">*</option>
 <option values="/">/</option>
 <option values="Mod">%</option>
</select>
<input type="text" name="txtNilai2">
<input type="submit" value="Hitung">
</form>
</body>
</html>

Proses
<?php
$n = $_POST['txtNilai1'];
$n2 = $_POST['txtNilai2'];
$op = $_POST['op'];

if (!is_numeric($n)) {
echo "data harus 0-9";
}else if (!is_numeric($n2)) {
echo "data pada nilai 2 harus 0-9";
}else{
if ($op=="+"){
$hasil = ($n + $n2);
}
else if($op=="-"){
$hasil = ($n - $n2);
}
else if($op=="*"){
$hasil = ($n * $n2);
}
else if($op=="/"){
$hasil = ($n / $n2);
}
else if($op=="Mod"){
$hasil = ($n % $n2);
}
echo "Hasil : $hasil";
}
?>

Written by

Hello , My name is Sony Surahman.I'am a newbie Blogger

0 komentar:

Posting Komentar

Tolong kalau komentar pake bahasa yang sopan ya... :)

© 2014 T-A_Blog'z. All rights resevered. Designed by Templateism | Edited by Me