Jump to content

Recommended Posts

<html>

 

<head>

<title></title>

</head>

<body>

<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">

<select name="trig">

<option value="sin">Sin ( )</option>

<option value="cos">Cos ( )</option>

<option value="tan">Tan ( )</option>

</select>

<select name="deg_rad">

<option value="rad">Radians</option>

<option value="deg">Degrees</option>

</select>

<input type="text" name="trig_value">

<input type="submit" value="Solve">

</form>

 

<?php

$find_trig = @$_POST['trig'];

$deg_rad = @$_POST['deg_rad'];

$trig_value = @$_POST['trig_value'];

$deg = rad2deg($trig_value);

 

if($find_trig == 'sin' && $deg_rad == 'rad')

echo (sin($trig_value));

else

if($find_trig == 'sin' && $deg_rad == 'deg')

echo $deg;

 

?>

 

I don't know what i am doing wrong. The radians works but when i try degrees i get a weird number.

</body>

</html>

Link to comment
https://forums.phpfreaks.com/topic/154811-deg2rad-wont-work/
Share on other sites

<html>

   <head>
      <title></title>
   </head>
   <body>
<form action="<?php echo $_SERVER['PHP_SELF']; ?>" method="post">
<select name="trig">
<option value="sin">Sin ( )</option>
<option value="cos">Cos ( )</option>
<option value="tan">Tan ( )</option>
</select>
<select name="deg_rad">
<option value="rad">Radians</option>
<option value="deg">Degrees</option>
</select>
<input type="text" name="trig_value">
<input type="submit" value="Solve">
</form>

<?php
$find_trig = $_POST['trig'];
$deg_rad = $_POST['deg_rad'];
$trig_value = ($_POST['deg_rad'] == 'rad')? $_POST['trig_value'] : deg2rad($_POST['trig_value']);

if($find_trig == 'sin')
{
echo (sin($trig_value));
}
else if($find_trig == 'tan'){
echo (tan($trig_value));
}
else if($find_trig == 'cos'){
echo (cos($trig_value));
}


?>
   </body>
</html>

 

try that...

Link to comment
https://forums.phpfreaks.com/topic/154811-deg2rad-wont-work/#findComment-819602
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.