hí friends am new to php and i know some basics in php and i want to write a calculator program and m looking for some clues please word is welcomed

Recommended Answers

All 6 Replies

you could try this code

<?php

/* Calculator */


if($submit)
{
   if($operator == '*')
   {
       echo $numa * $numb;
   } elseif($operator == '/')
   {
       echo $numa / $numb;
   } elseif($operator == '+')
   {
       echo $numa + $numb;
   } elseif($operator == '-')
   {
       echo $numa - $numb;
   }
} else { ?>
<form method="POST" action="<?php $_SERVER['PHP_SELF']; ?>">
 <input type="text" name="numa" size="10">
 <input type="text" name="operator" size="2">
 <input type="text" name="numb" size="10">
 <input type="submit" value="Calculate" name="submit">
</form>
<?php } ?>
Member Avatar for diafol

php doesn't make good calculators as you have to send data to the server on every button click, unless you use javascript as well that is. And if you do, you may as well do it all in javascript. I'm sure somebody here will have a go at me for saying that, but just my 2p.

You can however use a form to choose a train of operators and numbers, but that's just a fudge IMO.

tanx a lot @css will update you if i have any problem running the code
@diafol please can you help me out with the javascript code for writting a calculator program

This site features a snippet (if not the whole thing) in making a calculator using php:
Click Here

Member Avatar for diafol

@diafol please can you help me out with the javascript code for writting a calculator program

Go over to the javascript forum and post your question there. However, you need to show some effort yourself. Asking for code isn't really what this whole site is about. SHow your code, outlining problems and we then help. That's usually the way it works.

Asking for js help here is likely to get you half-cocked ideas from back-end developers :) No offence to the cross-over gurus that frequent this forum.

@diafol please can you help me out with the javascript code for writting a calculator program

(agreeing with diafol)

I hope you noticed that nobody will give you/write the code for you, we can only help you with what you have... that's the idea of learning with teachers... they can't do the work but can point out/guide you in getting something done.

Since you are looking for javascript code, have you by any chance googled the question? I found a php calculator with 2 seconds of typing on google and it was the first result...

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.