Jump to content

bored again - made a calculator


Skatecrazy1

Recommended Posts

wheee

[code]
<?php  $self = $_SERVER['PHP_SELF'];
          $operator = $_POST['radio'];
          $value1 = $_POST['value1'];
          $value2 = $_POST['value2'];
if(isset($operator)){
  if($operator == "*"){
    $final_value = $value1 * $value2;
  }
  elseif($operator == "/"){
    $final_value = $value1 / $value2;
  }
  elseif($operator == "+"){
    $final_value = $value1 + $value2;
  }
  elseif($operator == "-"){
    $final_value = $value1 - $value2;
  }
} else {
    $final_value = "";
}

?>

<form method="post" action="<?php echo $self; ?>">
First Value <input type="text" name="value1" />
<br />
+ <input type="radio" name="radio" value="+" />
- <input type="radio" name="radio" value="-" />
x <input type="radio" name="radio" value="*" />
/ <input type="radio" name="radio" value="/" />
<br />
Second Value <input type="text" name="value2" />
<br />
<input type="submit" value="Calculate" />
<br /><br />
Final Value: <input type="text" value="<?php echo $final_value; ?>" />
</form>
[/code]

see how what good use i put my time to....

hooray.
Link to comment
https://forums.phpfreaks.com/topic/25893-bored-again-made-a-calculator/
Share on other sites

[quote author=Daniel0 link=topic=113561.msg461546#msg461546 date=1162450725]
Here is a challenge for you then: Try to make a calculator where you can enter simple expressions and make it calculate it... Eg: 1+2*5
[/quote]

I suspect that's not quite what you're thinking of -

[code]<?php
echo(1+2*5);
?>[/code]

Shows 11. Just as it should.

[quote author=Crayon Violent link=topic=113561.msg461547#msg461547 date=1162450918]
or make a graphing calculator using the gd library.
[/quote]

+10 ninja points if you get this one. That would be super cool.
[quote author=neylitalo link=topic=113561.msg461552#msg461552 date=1162451710]
[quote author=Crayon Violent link=topic=113561.msg461547#msg461547 date=1162450918]
or make a graphing calculator using the gd library.
[/quote]

+10 ninja points if you get this one. That would be super cool.
[/quote]

hmm i have this sneaky feeling that someone has read that, and is hacking up some GD scripts as we speak...
[quote author=redbullmarky link=topic=113561.msg461599#msg461599 date=1162464896]
hmm i have this sneaky feeling that someone has read that, and is hacking up some GD scripts as we speak...
[/quote]

It's just a good thing that I don't have to give anything tangible. :) I heart imaginary rewards. Except when I'm getting them.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.