Jump to content

Output error


doucettej3

Recommended Posts

I cant get this code to output. I think theres something wrong with the variable $fav_temp but i cant figure out what.

This is the function its used in:

function vac_week($avg_array, $fav_temp)
{ 
$low = $fav_temp - 10;
$high = $fav_temp + 10;

for($k = 0; $k < 52; $k++)
{	
if($avg_array[$k] >= $low && $avg_array[$k] <= $high)
{
	echo 'Your Ideal vacation week is week ' . $k;
	}
	else
	{
	echo "noMatches";
	}



}
}

And This is the switch:

$action = $_GET['action'];
require('functions.php');
switch($action)
{
case 'generate':
$fav_temp = $_GET[‘fav_temp’];
$random_array = create_array(); 
$average = avg($random_array); 
$vacation = vac_week($avg_array, $fav_temp);

break;
default:
  ?>
  <table align="center">
  <form name="settingsFORM" action="index.php" METHOD=GET>
  <input type=HIDDEN name="action" value="generate">
  <tr><th colspan=2>Settings
  <tr><td>Favorite Temperature: <input type=TEXT name="fav_temp" size=1>
  <tr><td><input type=SUBMIT value="Continue >>">
  </form>
  </table>
  <?php
break;
}

Link to comment
Share on other sites

try

function vac_week($avg_array, $fav_temp)
{
$min = 10000;
$out = 10000;  
   for($k = 0; $k < 52; $k++) if(abs($avg_array[$k] - $fav_temp) < $min) {
        $out = $k;
        $min =  abs($avg_array[$k] - $fav_temp);
   }
   echo 'Your Ideal vacation week is week ' . $out;
}

Link to comment
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.