nschmutz Posted June 21, 2010 Share Posted June 21, 2010 I'm not sure how to create the code to represent a division problem. Here is what I have so far in the code. <html> <head> </head> <form action="schmutz_extra_01.php" method="POST"> <p>Please enter an integer that is divisible by 3:</p> <input type="text" name="number" value="<?php echo $_POST['integer'];?>"/></p> <input type="submit" name="submit" value="Calculate!" /> </form> <?php function divisible($n) { $result = ($n) % 3; return $result; } if (isset($_POST['integer'])) { $integer = $_POST['integer']; $div = divisible($integer); echo "Your entered " . $integer . " and the result is " . $div . "</br>"; } ?> </html> Quote Link to comment Share on other sites More sharing options...
Psycho Posted June 21, 2010 Share Posted June 21, 2010 And what is your problem? What is the code not doing that you want it to or what is it doing that you don't want? You didn't ask a question and I'm not sure from looking at the code what you are trying to accomplish. But, I will say that your function divisible() is only returning the remainder of the number divided by three - is that what you wanted? Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted June 21, 2010 Share Posted June 21, 2010 Are you trying to solve a division problem, or see if one integer is divisible by another integer? Quote Link to comment Share on other sites More sharing options...
nschmutz Posted June 21, 2010 Author Share Posted June 21, 2010 I am trying to display the results of the entered integer is divisible by 3 and have the form be 'sticky'. So far I have no errors but the form is not sticky and I am no getting any results to display. Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted June 21, 2010 Share Posted June 21, 2010 To begin with, you don't have a form field named 'integer', you have one named 'number' . . . Quote Link to comment Share on other sites More sharing options...
nschmutz Posted June 21, 2010 Author Share Posted June 21, 2010 Thanks for that catch of the name Pikachu2000, I made the correction now it does display the results but I need to work on the math problem itself. I just am confused on the logic of how to display the integer divided by 3. Quote Link to comment Share on other sites More sharing options...
Pikachu2000 Posted June 21, 2010 Share Posted June 21, 2010 To display result of the integer divided by 3 would be $integer = $_POST['number']; $integer = $integer / 3; echo $integer; To use the modulus operator to see IF the integer is divisible by 3, it would be $integer = $_POST['number']; if( ($integer % 3) == 0 ) { $divisible = "Divisible by 3"; } else { $divisible = "Not Divisible by 3"; } Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.