0

I am Trying to Creat a calculator in PHP. All other operator is working (ex:+,_,*,/) but only Modulus % operator is not working. Please solve this problem.

<form method="get">
    <input type="text" name="Number1"  placeholder="Enter Number One">
    <input type="text" name="Number2"  placeholder="Enter Number Two">
    <select name="operator">
            <option >Division</option>
            <option >Modulation</option>
    </select>
    <button type="submit" name="submit">Calculate</button>
</form>  

php Code is here:

<?php
    echo "<br> Your Result is : ";
      if(isset($_GET['submit'])){
        $result1=$_GET['Number1'];
        $result2=$_GET['Number2'];
        $operator=$_GET['operator'];

      switch($operator){

        case 'Division':
          echo $result1/$result2;
          break;
        case 'Modulation':
          echo $result1 % $result2;
          break;
      }
      }

    ?>
  • 3
    Welcome to SO! At present your question is impossible to answer because you haven't told us anything other than "it doesn't work". More detail - such as input data, expected output and actual output is needed. Please read [ask] and then [edit] your question. Thanks. – Nick Feb 23 '19 at 04:33
  • Keep in mind that % will convert any input to integers, truncating any decimal points: http://php.net/manual/en/language.operators.arithmetic.php – Russ J Feb 23 '19 at 04:45

0 Answers0