Loading...


bookmark - Making Calculators with PHP Some basic calculator scripts I made.

Making Calculators with PHP - Some basic calculator scripts I made.

 
 Discussion by BuBBaG with 6 Replies.
 Last Update: June 13, 2011, 5:11 pm ( View Rated (1) )
 
bookmark - Making Calculators with PHP Some basic calculator scripts I made.  
Quickly Post to Making Calculators with PHP Some basic calculator scripts I made. w/o signup Share Info about Making Calculators with PHP Some basic calculator scripts I made. using Facebook, Twitter etc. email your friend about Making Calculators with PHP Some basic calculator scripts I made. Print
Reply / Comment New Discussion / Topic Share / Bookmark E-Mail a Friend Print

Yes, I made some basic calculators to use for simple math problems, nothing big.
I'm a newbie at php, so if I made something that could be short, long, I am sorry. lol
Here is one for adding two numbers.

CODE

<html>
<title>Adding 2 numbers </title>
<body>
<h3 align="center">Type in the two numbers you'd like to add together.</h3>


<form action="add2.php" method="post">
<input type="text" name="number1" /><p>+</p>
<input type="text" name="number2" />
<input type="submit" value="Add!" />
</form>


</body>
</html>

Save that and name it add.php or add.html, it don't matter.
In that page, it is simply asking for 2 numbers to add.

Next, create a page called add2.php, can't make it html.

CODE

<?php
$_POST["number1"];
$_POST["number2"];
?>
<html>
<title>Answer to <?php echo $_POST["number1"]; ?> + <php echo $_POST["number2"]; ?></title>
<body>
<h3 align="center">Answer to <?php echo "$_POST["number1"]; ?> + <php echo $_POST["number2"]"; ?></h3>

<p> The answer to
<?php
echo $_POST["number1"]; ?> + <php echo $_POST["number2"];
?>
is <?php echo $_POST["number1"]+$_POST["number2"];
?>
</body>
</html>

Php files can have html in them.lol
What this page is doing is adding the two numbers that were inputed on add.php(what I used).
Simple right?
Here is subtraction, for this, I copied and pasted the adding script/pages and made new ones called subtract.php, for the first one and subtract2.php for the second. I changed the adding to subtracting and yeah.

CODE

<html>
<title>Subtracting 2 numbers </title>
<body>
<h3 align="center">Type in the two numbers you'd like to subtract.</h3>


<form action="subtract2.php" method="post">
<input type="text" name="number1" /><p>-</p>
<input type="text" name="number2" />
<input type="submit" value="Subtract!" />
</form>


</body>
</html>

And

CODE

<?php
$_POST["number1"];
$_POST["number2"];
?>
<html>
<title>Answer to <?php echo $_POST["number1"]; ?> - <php echo $_POST["number2"]; ?></title>
<body>
<h3 align="center">Answer to <?php echo "$_POST["number1"]; ?> - <php echo $_POST["number2"]"; ?></h3>

<p> The answer to
<?php
echo $_POST["number1"]; ?> - <php echo $_POST["number2"];
?>
is <?php echo $_POST["number1"]-$_POST["number2"];
?>
</body>
</html>


yeah.
I also made a calculator for finding a circles area and circumference with just entering the diameter.

First, make a file called circle.php, copy and paste this code in it.

CODE

<html>
<title>Enter the Diameter </title>
<body>
<h3 align="center">What is this circles circumference and area?</h3>
<p>
Just enter the diameter.</p>

<form action="circle2.php" method="post">
Diameter(d): <input type="text" name="d" />
<input type="submit" value="Submit" />
</form>


</body>
</html>


Next, make a file named circle2.php. In it, it will solve for area and circumference using two formulas.
Where
D=diameter
R=radius
C=circumference
A=area.

For circumference;
D*pi=C

For area;
pi*®^2=A
Unless I'm horrible at math, those are false, but I'm excellent at math, so no worries.

Now, to make that file.

CODE

<html>
<title>Area and Circumference </title>
<body>
<h3 align="center">Answers to Area/Circumference</h3>
<?php $_POST["d"];
?>

<?php
$d=$_POST["d"];
$r=$d/2;
$r2=$r*$r;
$pi=pi();
?>
<p>The aree and circumference of a circle with a diameter of <?php echo $d; ?> are<br />
Area:<?php
echo $pi*$r2;
?><br />
Circumference:<?php
echo $pi*$d;
?>


</p>


</body>
</html>

Now, just copy and paste, and it works.

For multiplication and devision, change the + or - to * or /.
Adding is +
Subtracting is -
Multiplying is *
Dividing is /

If you have any questions, feel free to ask. I'll also make a calculator at request, just post the formula for it, I'll make it and test it first, then give you the codes.

Yours truly,
Bubba.

   Fri Jun 27, 2008    Reply         

I think it would be a lot beter, if you put in a button, which allowed you to choose the operator, so a minus button, a luse button, and multiply and divide buttons.
It shouldn't be too hard to do, you would just have to make the page, use a different PHP script, depending on which button you pressed.

Or you could use radio buttons (actually thi would probably be beter)

   Fri Jun 27, 2008    Reply         

nice, thats cool.

I like the last piece of code, howto on calculation areas, never thought about that with php.

PHP Supports nice math functions, im sure with php its possible to make great calculators.

You could use radio buttons yes, but its also possible to make real buttons, using winbinder, then compile to executable

I belive winbinder has a example on howto make an real calculator application using php
Oh found it, here you go http://winbinder.org/examples.php


- optiplex







   Fri Jun 27, 2008    Reply         


Well, for a better calculator, use Javascript for basic operations, and PHP for complex ones using AJAX as well. Nice script though.

   Fri Jun 27, 2008    Reply         

Thank you guys. ;)
I don't wanna do buttons or anything cause I'll like get confused. lol.
I'm not too good with html.

   Sat Jun 28, 2008    Reply         

How to make a calculator program that user can choose how many digits they want to calculate? for example, 3 + 4 * 12?

   Sun Feb 13, 2011    Reply         


great work bubba,are you able to build me a calculator for simple multiplication of 2 figures?
Just like the one shown here: http://www.curtainscurtainscurtains.co.uk/serenity-natural-pid12204-cid6.html

   Mon Jun 13, 2011    Reply         

First of all, nobody is going to do your homework for you. If you have questions, you should ask your teacher/instructor/professor. That said, I'll give you a few suggestions for things to look at:
-You need to have a basic understanding of how forms work. Read this:
http://www.w3schools.com/html/html_forms…

-You need to have a basic understanding of how to read form data in php. See:
http://www.w3schools.com/php/php_get.asp
http://php.net/manual/en/reserved.variab…

And yes, you can output the form in the same php script that you submit that form to. If you have other questions, email your teacher. Nobody here is going to help you cheat any more than your teacher would, and by asking your teacher you'll know what s/he actually expects.

   Mon Oct 17, 2011    Reply         

Quickly Post to Making Calculators with PHP Some basic calculator scripts I made. w/o signup Share Info about Making Calculators with PHP Some basic calculator scripts I made. using Facebook, Twitter etc. email your friend about Making Calculators with PHP Some basic calculator scripts I made. Print
Reply / Comment New Discussion / Topic Share / Bookmark E-Mail a Friend Print

Similar Topics:

Ti Basic: Pick A Number

Description Learn how to create a neat-o Game in TI Basic. Its basic premise is that someone picks a number, then they pass the calculator to their friend, and they try to guess the number. Once the successfully guess the number a message appears and says that they have won. I ha ...more

   14-Apr-2008    Reply         

Need Help Setting Up Php Scripts

hi everyone, I have some PHP scripts written for my clan's website, written and distributed for free by Clan Overdosed... Anyways, I'm not sure how to get the site up and running, uploading the files, and then the website pulling them up, any help is appreciated... I've hear ...more

   05-Jan-2009    Reply         

Php Bug Tracking System

Do you have some trouble in tracking bugs to your site usually? Download Free and open source PHP Bug Tracking System Projects. These PHP Projects allow you to build a bug tracking system to track bugs and ...more

   10-Mar-2011    Reply         

How To Control Other Users’ Privileges (microsoft Windows Steadystate 2.5)    How To Control Other Users’ Privileges (microsoft Windows Steadystate 2.5) (4) (7) How To Disable Firefox's Awesome Bar restore old location/address bar from firefox 2  How To Disable Firefox's Awesome Bar restore old location/address bar from firefox 2