Page 1 of 1

Why doesnt this work?

Posted: Mon Jun 16, 2008 8:27 pm
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>";
          }
        }
      }
    }
  }
}
 
 
?>
 

Re: Why doesnt this work?

Posted: Tue Jun 17, 2008 6:57 am
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!