0

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

4
Contributors
6
Replies
8
Views
4 Years
Discussion Span
Last Post by <M/>
0

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 } ?>

Edited by cssweb

1

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.

Edited by diafol

0

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

1

@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.

Edited by diafol

0

@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...

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.