Temperatures puzzle discussion


#694

(PHP) Tous les tests passent dans la page de code à 100%. et seulement 85 % après soumission sur question 2 et 3.
(PHP) all code example passed in dev hud. but after submiting only 85 % . any clue ?


#695
 int CT=abs(temp[0]);
    int j=sizeof(temp);
    for(int i=0;i<n;i++)
    {
        if(CT>abs(temp[i]))
        {
            CT=abs(temp[i]);
             p=i;
            
        
        }
    }
    for(int i=0;i<n;i++)
    {
        if(CT==abs(temp[i]))
        {
            if(temp[p]<temp[i])
            {
                CT=temp[i];
            }
        }
        else
        {
            CT=temp[p];
        }
    }

whats the problem with this code i cant get through the the 3 test case everything else does work


#696

I advise you to add “error prints” to your algorithm to know the values of CT and p for example. You’ll quickly see the mistake in your code. Good luck!


#697

Thanks! That did it. My code has a section that tests if the input is numeric, and sets the output to zero if that’s the case. The initial input values are string values, not integers. I ran intval() on the input value first, and it works now.