Welcome Guest ( Log In | Register)



 
Reply to this topicStart new topic
> Making Calculators with PHP, Some basic calculator scripts I made.
BuBBaG
post Jun 27 2008, 09:27 AM
Post #1


Newbie [Level 1]
*

Group: [HOSTED]
Posts: 18
Joined: 12-June 08
Member No.: 63,526



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.
Go to the top of the page
 
+Quote Post
minimcmonkey
post Jun 27 2008, 03:42 PM
Post #2


Super Member
*********

Group: [HOSTED]
Posts: 224
Joined: 19-June 08
From: United Kingdom - Cornwall!!!!!
Member No.: 63,876



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)
Go to the top of the page
 
+Quote Post
optiplex
post Jun 27 2008, 04:58 PM
Post #3


Newbie [Level 3]
***

Group: [HOSTED]
Posts: 40
Joined: 26-June 08
Member No.: 64,213



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

This post has been edited by optiplex: Jun 27 2008, 05:01 PM
Go to the top of the page
 
+Quote Post
coolcat50
post Jun 27 2008, 06:27 PM
Post #4


Super Member
*********

Group: Members
Posts: 290
Joined: 5-October 07
From: Random Places
Member No.: 51,171
Spam Patrol



Well, for a better calculator, use Javascript for basic operations, and PHP for complex ones using AJAX as well. Nice script though.
Go to the top of the page
 
+Quote Post
BuBBaG
post Jun 28 2008, 02:51 AM
Post #5


Newbie [Level 1]
*

Group: [HOSTED]
Posts: 18
Joined: 12-June 08
Member No.: 63,526



Thank you guys. tongue.gif
I don't wanna do buttons or anything cause I'll like get confused. lol.
I'm not too good with html.
Go to the top of the page
 
+Quote Post

Reply to this topicStart new topic

Collapse

> Similar Topics

Topics Topics
  1. Check Your Scripts(4)
  2. How To: Install Scripts And Create Database(2)
  3. Making A Webserver Directory Listing(6)
  4. Tutorial: Installing D-shoutbox For Ipb V1.2(12)
  5. Making Winrar Archives(13)
  6. Making And Editing A New Ipb V1.2 Skin [SPAM](2)
  7. How To: Make A Simple Php Site(21)
  8. Making Interactive Cds With Flash(2)
  9. Making A Dynamic Page On Blogspot(5)
  10. Fantastico Scripts - A 'how To'(0)
  11. Cpanel Preinstalled Scripts, Extras, And Cpanel Options(1)
  12. Simple Scripts In Html And Javascript(7)
  13. Making The Popular Id Browsing For Your Site.(17)
  14. Making a java based program(3)
  15. Making A One Page Does All Website In Phph(2)
  1. How To Install Php Scripts(0)
  2. Creating A Resume(1)
  3. Making A Song In Fruity Loops Part 2(0)
  4. Making A Song In Fruity Loops Part Three(1)
  5. Calculator In Mozilla Firefox(6)
  6. [php] Clean Code Functions(5)
  7. Ftp In Visual Basic 6.0(1)
  8. How To Make An Ultimate Game List.(0)


 



- Lo-Fi Version Time is now: 12th October 2008 - 03:14 AM