Jump to content

Output Error


doucettej3

Recommended Posts

This code doesnt output at all. I cant figure out whats wrong with it. Any help would be greatly appreciated.

function vac_week($avg_array, $fav_temp)
{ 

$k = 0;
while($k < 52)
{
if($avg_array[$k] <= ($fav_temp + 10) && $avg_array[$k] >= ($fav_temp - 10))
{
	echo 'Your Ideal vacation week is week ' . $k;

	}
	else
	{
	$k++;
	}
	}
}

Link to comment
Share on other sites

You need to call the function like this:

 

vac_week($array, $temp);

 

I think you will also need to break out of the loop when the ideal vacation week is found (if you only want to find one), otherwise do the $k++ outside of the "else".

 

Jordan: I saw your post before you edited, I will keep it secret :P

Link to comment
Share on other sites

function vac_week($avg_array, $fav_temp)
{
   
   $k = 0;
   while($k < 52) {
         if($avg_array[$k] <= ($fav_temp + 10) && $avg_array[$k] >= ($fav_temp - 10)) {
               echo 'Your Ideal vacation week is week ' . $k;
      
          }

          $k++;
          
    }
}

 

Infinite loop, if that condition is true the first time it will be true every time cause K was never incremented.

Link to comment
Share on other sites

I was thinking "It can't be less than and greater than at the same time" then I noticed the +10 and -10.

 

Exactly =)

 

EDIT: lol you edited it and now the above doesn't make sense.

 

Anyhow I was saying exactly to since it was an infinite loop the data was never posted to the browser cause it never stopped to do so.

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.