Current time: 12-19-2018, 06:18 PM Stay in touch via Twitter Facebook RSS Feed
Ada Baiknya anda baca Peraturan Forum ForNesia Disini Dan Disitu Sebelum Terlambat!
System Registration Forums Mulai Kedepan Sewaktu waktu akan Di Tutup.
Silahkan Dibaca Mengenai Auto Pruning User . Agar tidak ada pertanyaan lagi tentang kehilangan akses forum.



[Share] Contoh sederhana perhitungan di PHP

09-22-2014 10:48 PM Contoh sederhana perhitungan di PHP
#1


dokgabriel Away
Programer Tamfan
FNS Member
**

Posts: 163
Joined: Jul 2014

Reputation:

FCoin: 11.40ƒc
Code:
<?php
$penjumlahan = 2+4;
$pengurangan = 6-2;
$perkalian = 6*3;
$pembagian = 15/3;
$modulus = 5%2;
echo "Menampilkan hasil perjumlahan 2 + 4 = ".$penjumlahan."<br>";
echo "Menampilkan hasil pengurangan 6 - 2 = ".$pengurangan."<br>";
echo "Menampilkan hasil perkalian 6 * 3 = ".$perkalian."<br>";
echo "Menampilkan hasil pembagian 15 : 3 = ".$pembagian."<br>";
echo "Menampilkan hasil modulus 5 % 2 = ".$modulus."<br>";
?>
ntar hasil nya kayak gini
Spoiler :
[Image: Screenshot_198.png]
(This post was last modified: 09-22-2014 10:59 PM by dokgabriel.)
10-02-2014 09:45 PM RE: Contoh sederhana perhitungan di PHP
#2


userbo Away
HunteR
HunteR
*

Posts: 49
Joined: Mar 2014

Reputation:

FCoin: 3.06ƒc
(09-22-2014 10:48 PM)dokgabriel Wrote:  
Code:
<?php
$penjumlahan = 2+4;
$pengurangan = 6-2;
$perkalian = 6*3;
$pembagian = 15/3;
$modulus = 5%2;
echo "Menampilkan hasil perjumlahan 2 + 4 = ".$penjumlahan."<br>";
echo "Menampilkan hasil pengurangan 6 - 2 = ".$pengurangan."<br>";
echo "Menampilkan hasil perkalian 6 * 3 = ".$perkalian."<br>";
echo "Menampilkan hasil pembagian 15 : 3 = ".$pembagian."<br>";
echo "Menampilkan hasil modulus 5 % 2 = ".$modulus."<br>";
?>
ntar hasil nya kayak gini
Spoiler :
[Image: Screenshot_198.png]

mungkin begini akan lebih enak mbak ^_^
Spoiler :

<style>
#opr{
margin-left :130px;
}
#atas{
margin-top:20px;
margin-left:20px;
}
#sub{
margin-left :122px;
}
</style>
<div id="atas">
<form method="post" action="hitung.php">
<div id ="x">
Masukkan Nilai X : <input required autofocus type="number" type="text" name="number1" >
</div>
<div id="opr">
<select name="operator" required>
<option value="" >Pilih Operator</option>
<option value="+">+</option>
<option value="-">-</option>
<option value="*">*</option>
<option value="/">/</option>
</select>
</div>
<div id="y">
Masukkan Nilai Y : <input required autofocus type="number" type="text" name="number2" >
</div>
<div id="sub">
<input type="submit" name="submit" value="Hitung">
</div>
<?php
class Calculator {

var $sum;
var $dif;
var $multi;
var $div;

function penjumlahan($number1, $number2) {
$this->tambah = $number1 + $number2;
}

function pengurangan($number1, $number2) {
$this->kurang = $number1 - $number2;
}

function perkalian($number1, $number2) {
$this->kali = $number1 * $number2;
}

function pembagian($number1, $number2) {
$this->bagi=$number1 / $number2;
}

}
error_reporting(E_ALL ^ (E_NOTICE | E_WARNING));
$number1 = $_POST['number1'];
$number2 = $_POST['number2'];
$op = $_POST['operator'];
$hasil = new Calculator();

if ( $hasil->penjumlahan($number1,$number2));
else if( $hasil->pengurangan($number1,$number2));
else if( $hasil->perkalian($number1,$number2));
else if( $hasil->pembagian($number1,$number2));

if($op=='+'){
echo "$number1 + $number2 = ".$hasil->tambah." <br>";
}

else if($op=='-'){
echo "$number1 - $number2 = ".$hasil->kurang." <br>";
}

else if($op=='*'){
echo "$number1 * $number2 = ".$hasil->kali." <br>";
}

else if($op=='/'){
echo "$number1 / $number2 = ".$hasil->bagi." <br>";
}

?>
</form>
</div>
(This post was last modified: 10-02-2014 09:46 PM by userbo.)
10-13-2014 03:47 AM RE: Contoh sederhana perhitungan di PHP
#3


yusuvinside
Unregistered

 
FCoin: 0.00ƒc
nyimak gan..baru belaar PHP
11-12-2014 02:18 AM RE: Contoh sederhana perhitungan di PHP
#4


nyonyo Away
HunteR
HunteR
*

Posts: 50
Joined: Feb 2014

Reputation:

FCoin: 2.00ƒc
alangkah baikknya dijelaskan semua variable yang digunakan @TS biar yang belajar tau gunanya..tidak hanya meniru ketawaaa
Just Saran..but nice Thread Smile
12-13-2014 11:53 AM RE: Contoh sederhana perhitungan di PHP
#5


djtechwork Away
HunteR
HunteR
*

Posts: 40
Joined: Dec 2014

Reputation:

FCoin: 2.20ƒc
Kalo bs tolong share yang OOP mas.. Klo coding cara tradisional sy sdh agak ngerti, yang OOP masih gk mudeng.
12-14-2014 02:05 AM RE: Contoh sederhana perhitungan di PHP
#6


vinazerd Away
FNS MEMBER
FNS Member
**

Posts: 200
Joined: Dec 2014

Reputation:

FCoin: 24.46ƒc
kalau PHP lewat mane taro skripsnya gan?
04-06-2015 09:29 AM RE: Contoh sederhana perhitungan di PHP
#7


userbo Away
HunteR
HunteR
*

Posts: 49
Joined: Mar 2014

Reputation:

FCoin: 3.06ƒc
(12-13-2014 11:53 AM)djtechwork Wrote:  Kalo bs tolong share yang OOP mas.. Klo coding cara tradisional sy sdh agak ngerti, yang OOP masih gk mudeng.

bukannya yg ane share itu yg oop bukan ya ? :mikir:

userbo, proud to be a member of ForNesia Family since Mar 2014.
04-06-2015 10:48 AM RE: Contoh sederhana perhitungan di PHP
#8


aviator Away
Royalty Member
Royalty Member
**

Posts: 898
Joined: Mar 2014

Reputation:

FCoin: 3,741.99ƒc

(10-02-2014 09:45 PM)userbo Wrote:  mungkin begini akan lebih enak mbak ^_^

ini buat apaan gan?
Spoiler :
var $sum;
var $dif;
var $multi;
var $div;
ini jg buat apaan gan?
Spoiler :
if ( $hasil->penjumlahan($number1,$number2));
else if( $hasil->pengurangan($number1,$number2));
else if( $hasil->perkalian($number1,$number2));
else if( $hasil->pembagian($number1,$number2));

class calculator setelah ane edit:
Spoiler :
PHP Code:
class Calculator {
function 
penjumlahan($n1$n2) {return $n1 $n2;}
function 
pengurangan($n1$n2) {return $n1 $n2;}
function 
perkalian($n1$n2) {return $n1 $n2;}
function 
pembagian($n1$n2) {return $n1 $n2;}
}

$n1 $_POST['number1'];
$n2 $_POST['number2'];
$h = new Calculator();

switch(
$_POST['operator']):
    case 
'+':
        echo 
"$n1 + $n2 = ".$h->penjumlahan($n1,$n2);
    break;
    case 
'-':
        echo 
"$n1 - $n2 = ".$h->pengurangan($n1,$n2);
    break;
    case 
'*':
        echo 
"$n1 * $n2 = ".$h->perkalian($n1,$n2);
    break;
    case 
'/':
        echo 
"$n1 / $n2 = ".$h->pembagian($n1,$n2);
    break;
endswitch; 

atau yang g pake function, mirip post #1
Spoiler :
PHP Code:
$n1 $_POST['number1'];
$n2 $_POST['number2'];

switch(
$_POST['operator']):
    case 
'+':
        echo 
"$n1 + $n2 = ".($n1+$n2);
    break;
    case 
'-':
        echo 
"$n1 - $n2 = ".($n1-$n2);
    break;
    case 
'*':
        echo 
"$n1 * $n2 = ".($n1*$n2);
    break;
    case 
'/':
        echo 
"$n1 / $n2 = ".($n1/$n2);
    break;
endswitch; 

[Image: 0yiydbV.gif]
06-16-2015 11:46 PM RE: Contoh sederhana perhitungan di PHP
#9


dzoxy Away
ForNesia Family
Registered
*

Posts: 10
Joined: Jun 2015

Reputation:

FCoin: 2.00ƒc
(12-14-2014 02:05 AM)vinazerd Wrote:  kalau PHP lewat mane taro skripsnya gan?

instal xampp terus bikin folder baru di htdocs taro filenya disitu
06-17-2015 12:07 AM RE: Contoh sederhana perhitungan di PHP
#10


Donie Away
Baru Belajar
Registered
*

Posts: 2
Joined: May 2015

Reputation:

FCoin: 2.00ƒc
(06-16-2015 11:46 PM)dzoxy Wrote:  
(12-14-2014 02:05 AM)vinazerd Wrote:  kalau PHP lewat mane taro skripsnya gan?

instal xampp terus bikin folder baru di htdocs taro filenya disitu

mf gan oot.
kl mau buat post gimana ya. muter" gak jumpa"
hehe mf nubi berat gan. -_- :3
06-17-2015 01:16 AM RE: Contoh sederhana perhitungan di PHP
#11


asepmukarom Away
FNS MEMBER
FNS Member
**

Posts: 298
Joined: Feb 2015

Reputation:

FCoin: 13.95ƒc
itu ts ma ss y ko beda om?
yg asli yg pke ss ea...

di ss y lngkap bwat nampilin smua y tp di coding y cma nmpilin penjumblahan n pngurangan za gda klanjutan y..

asepmukarom, proud to be a member of ForNesia Family since Feb 2015. dan saya suka Kimcil.
06-17-2015 11:44 AM RE: Contoh sederhana perhitungan di PHP
#12


dzoxy Away
ForNesia Family
Registered
*

Posts: 10
Joined: Jun 2015

Reputation:

FCoin: 2.00ƒc
(06-17-2015 12:07 AM)Donie Wrote:  
(06-16-2015 11:46 PM)dzoxy Wrote:  
(12-14-2014 02:05 AM)vinazerd Wrote:  kalau PHP lewat mane taro skripsnya gan?

instal xampp terus bikin folder baru di htdocs taro filenya disitu

mf gan oot.
kl mau buat post gimana ya. muter" gak jumpa"
hehe mf nubi berat gan. -_- :3

maaf vrohh ane juga new disini, mungkin agan laen bisa bantu..
06-24-2015 07:09 AM RE: Contoh sederhana perhitungan di PHP
#13


userbo Away
HunteR
HunteR
*

Posts: 49
Joined: Mar 2014

Reputation:

FCoin: 3.06ƒc
(04-06-2015 10:48 AM)aviator Wrote:  
(10-02-2014 09:45 PM)userbo Wrote:  mungkin begini akan lebih enak mbak ^_^

ini buat apaan gan?
Spoiler :
var $sum;
var $dif;
var $multi;
var $div;
ini jg buat apaan gan?
Spoiler :
if ( $hasil->penjumlahan($number1,$number2));
else if( $hasil->pengurangan($number1,$number2));
else if( $hasil->perkalian($number1,$number2));
else if( $hasil->pembagian($number1,$number2));

class calculator setelah ane edit:
Spoiler :
PHP Code:
class Calculator {
function 
penjumlahan($n1$n2) {return $n1 $n2;}
function 
pengurangan($n1$n2) {return $n1 $n2;}
function 
perkalian($n1$n2) {return $n1 $n2;}
function 
pembagian($n1$n2) {return $n1 $n2;}
}

$n1 $_POST['number1'];
$n2 $_POST['number2'];
$h = new Calculator();

switch(
$_POST['operator']):
    case 
'+':
        echo 
"$n1 + $n2 = ".$h->penjumlahan($n1,$n2);
    break;
    case 
'-':
        echo 
"$n1 - $n2 = ".$h->pengurangan($n1,$n2);
    break;
    case 
'*':
        echo 
"$n1 * $n2 = ".$h->perkalian($n1,$n2);
    break;
    case 
'/':
        echo 
"$n1 / $n2 = ".$h->pembagian($n1,$n2);
    break;
endswitch; 

atau yang g pake function, mirip post #1
Spoiler :
PHP Code:
$n1 $_POST['number1'];
$n2 $_POST['number2'];

switch(
$_POST['operator']):
    case 
'+':
        echo 
"$n1 + $n2 = ".($n1+$n2);
    break;
    case 
'-':
        echo 
"$n1 - $n2 = ".($n1-$n2);
    break;
    case 
'*':
        echo 
"$n1 * $n2 = ".($n1*$n2);
    break;
    case 
'/':
        echo 
"$n1 / $n2 = ".($n1/$n2);
    break;
endswitch; 

maaf mbah yang ini variabelnya kagak ada gunanya di hapus pun kagak masalah
Spoiler :
var $sum;
var $dif;
var $multi;
var $div;
kalau yang ini
Spoiler :
if ( $hasil->penjumlahan($number1,$number2));
else if( $hasil->pengurangan($number1,$number2));
else if( $hasil->perkalian($number1,$number2));
else if( $hasil->pembagian($number1,$number2));
untuk pembuatan objek selanjutnya (mungkin itu namanya mbah ane juga gak begitu paham kalau di suruh jelasinya) buahaha

userbo, proud to be a member of ForNesia Family since Mar 2014.
06-11-2016 03:10 PM RE: Contoh sederhana perhitungan di PHP
#14


phantom_vhite Away
HunteR
HunteR
*

Posts: 68
Joined: Jul 2014

Reputation:

FCoin: 4.43ƒc
emang apa keuntungannya pake OOP atau enggak gan ?

phantom_vhite, proud to be a member of ForNesia Family since Jul 2014.




Search thread:


[-]
Advertisement