Jump to content

Recommended Posts

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>

Link to comment
https://forums.phpfreaks.com/topic/205425-division-problem/
Share on other sites

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?

Link to comment
https://forums.phpfreaks.com/topic/205425-division-problem/#findComment-1075022
Share on other sites

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"; 
}

Link to comment
https://forums.phpfreaks.com/topic/205425-division-problem/#findComment-1075056
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.