newbe

12-09-2010, 02:58 AM

the idea is that the function to calculate the area to be used inside the function perimeter, so that the perimeter function handles all printing.

This is what I've done but it's not the same as what I have mentioned above.

What Should I do?

This is what I want to do

Create a method called "Area ()" that calculates the area of a rectangle.

Call the method "Area ()" method from within "perimeter ()", submit

length and width as an argument to the method "Area ()" and use these to

calculate the area. Modify Approach "perimeter () "so that it prints the perimeter

and area when the user presses the button "CALCULATE". No printing will be done in

Approach "Area () "

<body>

<h1>PHP-sida 4</h1>

<form action="php4.php" method="post">

<p>Längd: <input type="text" name="length" size="20" /></p>

<p>Bredd: <input type="text" name="width" size="20" /></p>

<p><input type="submit" value="CALCULATE" name="calc" /></p>

</form>

<?php

if (isset($_POST['calc']))

{

$length= $_POST['length'];

$width= $_POST['width'];

echo "length:" . $length. "<br><br>";

echo "width:" . $width. "<br><br>";

function perimeter($length, $width)

{

return 2* ($length+ $width);

}

$perimeter= perimeter($length, $width);

echo "perimeter:" . $perimeter. "<br>", "<br>";

function area($length, $width)

{

return $length* $width;

}

$area = area($length, $width);

echo "area:" . $area ;

}

?>

</body>

This is what I've done but it's not the same as what I have mentioned above.

What Should I do?

This is what I want to do

Create a method called "Area ()" that calculates the area of a rectangle.

Call the method "Area ()" method from within "perimeter ()", submit

length and width as an argument to the method "Area ()" and use these to

calculate the area. Modify Approach "perimeter () "so that it prints the perimeter

and area when the user presses the button "CALCULATE". No printing will be done in

Approach "Area () "

<body>

<h1>PHP-sida 4</h1>

<form action="php4.php" method="post">

<p>Längd: <input type="text" name="length" size="20" /></p>

<p>Bredd: <input type="text" name="width" size="20" /></p>

<p><input type="submit" value="CALCULATE" name="calc" /></p>

</form>

<?php

if (isset($_POST['calc']))

{

$length= $_POST['length'];

$width= $_POST['width'];

echo "length:" . $length. "<br><br>";

echo "width:" . $width. "<br><br>";

function perimeter($length, $width)

{

return 2* ($length+ $width);

}

$perimeter= perimeter($length, $width);

echo "perimeter:" . $perimeter. "<br>", "<br>";

function area($length, $width)

{

return $length* $width;

}

$area = area($length, $width);

echo "area:" . $area ;

}

?>

</body>