Creating Basic Arithmetic Program Using PHP with Logic Function IF
In this tutorial I will explain about Program Basic Arithmetic For Plus, Minus, Multiply and divided With PHP Using Logic Function "IF"
PHP is a programming language that is often used to create a web that is combined with HTML tags, PHP running on the Server side, developed in 1995 by Rasmus Lerdorf. And this time I will make arithmetic program with php using Logic function "IF". The "IF" function is a function for checking a condition. Arithmetic is elementary mathematic count is the science which has the basic elements as follows: Plus (+), Minus (-), Divided (/), Multiply(x). And the steps we must do to make the Arithmetic Program are as follows :
1. Creating File Interface.php
We will create two Files to create this arithmetic program, the first one for the input page of numbers and the second page for processing the arithmetic program calculation. The first file is a form to input data numbers, and the following is the first form that we named file "interface.php"
the contents of file "interface.php" is as below:
<html>
<head>
<title>Program Aritmatik</title>
</head>
<body>
<center>
<form name="Arithmetic Program" method="post" action="process.php">
<table border="1">
<tr><td height="37" colspan="6" bgcolor="#0099FF"><center><strong>Basic Arithmetic Program</strong></center></td></tr>
<tr><td width="188">First Number Input</td><td width="8"><strong>:</strong></td>
<td colspan="4"><input name="input1" type="text" id="input1"></td></tr>
<tr><td height="26">Second Number Input</td><td><strong>:</strong></td>
<td colspan="4"><input name="input2" type="text" id="input2"></td></tr>
<tr><td>Select Operator</td><td> </td>
<td width="82"><label><input name="cal1" type="radio" value="plus"></label>+ (Plus) </td>
<td width="98"><label><input name="cal2" type="radio" value="minus"></label>- (Minus)</td>
<td width="89"><input name="cal3" type="radio" value="multiply">x (Multiply)</td>
<td width="121"><label><input name="cal4" type="radio" value="divided">: (Divided) </label></td>
</tr>
<tr>
<td> </td>
<td> </td>
<td colspan="4"><input name="Process" type="submit" id="Process" value="Process"></td>
</tr>
</table>
</form>
</center>
</body>
</html>
The most important code line in this program Arithmetic is the placement of variables for the first number, and the variable for the second number, the first variable we can see as follows, with the variable name is input1:
<input name="input1" type="text" id="input1">
And for the second number variable is given the name input2, like the following html code:
<input name="input2" type="text" id="input2">
and the naming of variables for the operator selection of this arithmetic program is as follows:
<td width="82"><label><input name="cal1" type="radio" value="plus"></label>+ (Plus) </td>
<td width="98"><label><input name="cal2" type="radio" value="minus"></label>- (Minus)</td>
<td width="89"><input name="cal3" type="radio" value="multiply">x (Multiply)</td>
<td width="121"><label><input name="cal4" type="radio" value="divided">: (Divided) </label></td>
all the inputs on the file interface.php will be directed to the file "process.php", as the following code:
<form name="Arithmetic Program" method="post" action="process.php">
2.Creating File Process.php
This will be done on a file the process calculation of input has been given, and the contents of "process.php" which is very important is part of the code if logic function, the following code file "process.php", as follows:
<?php
if ($cal1 == "plus") {
$svar = $input1 + $input2;
} else if ($cal2 == "minus") {
$svar = $input1 - $input2;
} else if ($cal3 == "multiply") {
$svar = $input1 * $input2;
} else if ($cal4 == "divided") {
$svar = $input1 / $input2;
}
?>
and the whole of the file "process.php" is as follows:
<html>
<head>
<title>Result</title>
</head>
<body>
<p>
<?php
if ($cal1 == "plus") {
$svar = $input1 + $input2;
} else if ($cal2 == "minus") {
$svar = $input1 - $input2;
} else if ($cal3 == "multiply") {
$svar = $input1 * $input2;
} else if ($cal4 == "divided") {
$svar = $input1 / $input2;
}
?>
</p>
<p> </p>
<p> </p>
<p> </p>
<p>
<center>
<strong>The Result is</strong> : <?php echo "$svar";?></p>
<p> <a href="interface.php">Main Program </a></p>
</body>
</html>
The "$svar" variable will hold from each calculation process performed and displayed as output by using the echo command, and the following code as follows :
<?php echo "$svar";?>
3.Proof of My Work
and the following as proof of my work, and the display of this image is animated GIF. when I run the program
may be useful
Posted on Utopian.io - Rewarding Open Source Contributors
good source
Follow me @zahidzzs
very informative post....
thanks for sharing it...
upvoted and followed..!!
Thanks for your comment
Good tutorial....
Good learning, and very informatif..
Sukses selalu @slempase....
Terima kasih @boyelleq
Thank you for the contribution. It has been approved.
You can contact us on Discord.
[utopian-moderator]
Thank you @syedumair
Hey @slempase I am @utopian-io. I have just upvoted you!
Achievements
Suggestions
Get Noticed!
Community-Driven Witness!
I am the first and only Steem Community-Driven Witness. Participate on Discord. Lets GROW TOGETHER!
Up-vote this comment to grow my power and help Open Source contributions like this one. Want to chat? Join me on Discord https://discord.gg/Pc8HG9x
Thank you utopian-io