| Calculator in php |
Code For Calculator In PHP
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
| <?php//The following is the <span id="IL_AD1" class="IL_AD">calculator</span> code:ini_set('display_errors',0); //ini_set for error reportingif( isset( $_REQUEST['<span id="IL_AD3" class="IL_AD">calculate</span>'] ))//isset check whether value is null or not.{$operator=$_REQUEST['operator'];if($operator=="+")// add operator{$add1 = $_REQUEST['fvalue']; // getting <span id="IL_AD7" class="IL_AD">values of</span> <span id="IL_AD4" class="IL_AD">html form</span>$add2 = $_REQUEST['lvalue']; // getting values of html form$res= $add1+$add2;//adding values}if($operator=="-")//subtracting operator{$add1 = $_REQUEST['fvalue'];// getting values of html form$add2 = $_REQUEST['lvalue'];// getting values of html form$res= $add1-$add2;//subtracting values}if($operator=="*")//multiplication operator{$add1 = $_REQUEST['fvalue'];// getting values of html form$add2 = $_REQUEST['lvalue'];// getting values of html form$res =$add1*$add2;//<span id="IL_AD11" class="IL_AD">multiply</span> values}if($operator=="/")//<span id="IL_AD9" class="IL_AD">divide</span> operator{$add1 = $_REQUEST['fvalue']; // getting values of html form$add2 = $_REQUEST['lvalue']; // getting values of html form$res= $add1/$add2;//divide values}}?><form> // html formEnter First Number<input name="fvalue" type="text">Select Operator <select name="operator"><option>+</option><option>-</option><option>*</option><option>/</option></select>Enter Second Number<input name="lvalue" type="text"/><input type="submit" name="calculate"value="Calculate" />Output =<?php echo $res;?>// output <span id="IL_AD2" class="IL_AD">results</span></form> |
Output (Screenshot1) :-
In this example i had made calculator to calculate two values foraddition, subtraction,Multiplication, Division.
Refer Articles : – Assignment Operators In Php , Arithmetic operators In Php , Comparison operators In Php , Logical Operators in Php, If_else If Statement , Variables In PHP , Echo Statement You can see this articles for detail study of programming php which i had used for making calculator in php.
Read More On Extra Tutorials
No comments:
Post a Comment