Why doesnt this work?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
NachoF
Forum Newbie
Posts: 1
Joined: Mon Jun 16, 2008 8:19 pm

Why doesnt this work?

Post by NachoF »

I was trying (long explanation as to why) to find out all the possible combinations to get below 9.5 but above 8.5 as the final grade of a course that consists on three tests, two quizes and extra points if you get 10 or more on each test (0.5, 0.5 and 1 extra point respectively).... I tried this very simple algorithm but for odd reason the highest grade its 18, not 20..... it appears to not be adding the extra 0.5s and 1... any help appreciated.

Code: Select all

 
<?php
 
for($i=0;$i<=20;$i++)
{
$definitiva=0;
  for ($j=0;$j<=20;$j++)
  {
  $definitiva=0;
    for ($k=0;$k<=20;$k++)
    {
    $definitiva=0;
      for ($l=0;$l<=20;$l++)
      {
      $definitiva=0;
        for ($m=0;$m<=20;$m++)
        {
        $definitiva=0;
        $definitiva=($i/4)+($j/4)+($k*3/10)+($l/20)+($m/20);
        if($i>=10)
          {
          $definitva+=0.5;
          }
         if($j>=10)
          {
          $definitva+=0.5;
          }
          if($k>=10)
          {
          $definitva++;
          }
          if($definitiva>17)//($definitiva>=8.5)&&($definitiva<9.5))
          {
 echo "Has podido sacar " . $i . " , " . $j. " , " . $k . " en los parciales y ". $l ." , " . $m . " en los talleres y te daba ".$definitiva ."<br>";
          }
        }
      }
    }
  }
}
 
 
?>
 
WebbieDave
Forum Contributor
Posts: 213
Joined: Sun Jul 15, 2007 7:07 am

Re: Why doesnt this work?

Post by WebbieDave »

It is difficult for me to understand the problem you are trying to solve as you've explained it. Regardless, you should determine for yourself if this is a PHP code problem, or a flaw inherent in the algorithm you've implemented. If the latter, you can step through your algorithm with well placed echo statements to better discover where things are going awry. Best of luck!
Post Reply