Ephp tutorial with dapeeyg( how to build a simple calculator)

in #utopianio6 years ago (edited)

What Will I Learn?
• You will learn to build a calculator using php
Requirements

• Micromedia Dreamweaver8
• WAMP Server

Difficulty
• Intermediate
Tutorial Contents
Hi guys, I will showing here how to build a simple calculator, which can be easily added to any ongoing project which needs such operator.
Design
To begin with, we'll be creating forms for each of the entities we will be considering in the program

  1. Add forms, after connecting your Wamp Server and Opening your forms. Creat two(2)text forms for imput,

  1. After which you create a select form using the drop down menu for the select option. Forms to be created in this category is 5, which are

  1. The last thing we will be doing here on the design is adding the submit button which is later changed to calculate. To create that just type;

Here is the screenshots for the entire design code for the program.

Firstly we have to open the php tag, then under the php code we have the ‘if statement’ then insisde the if statement we open a parenthesis and inside that we set our variables, and we set that to get the variables that have been set as you can see in the screenshot

I made use of an “if statement” which means each time you hit the submit button,it automatically makes the equation and display the output.
Also I made use of the “switch statement” at the later end of the program. You may be worried why I used the “switch statement” it has same function with the “if statement”.

if (isset($_GET['submit'])) { // to set your vairable output on the submitt button
$result1 = $_GET['num1'];
$result2 = $_GET['num2'];
$operator = $_GET['operator'];
switch ($operator){ // a switch statement also has same function with the if statement, either of the two can be used.
case "None":
echo "A method is required to be selected!"; // if no operation it chosen, the comment "A method is required to be selected"
break;


Run the code and insert variables in the text fields, choose a method then click on calculate button below as shown in the screenshot

If a method is not chosen during the operation an error message will pulp up ,which is shown on the screenshot below

Coin Marketplace

STEEM 0.30
TRX 0.12
JST 0.033
BTC 64534.17
ETH 3150.15
USDT 1.00
SBD 4.01