This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

Not the right answer

I do not see the right answer when i use this function.

float comppoly(x)
{ float y1,y2;
float a1=0.1,b1=0.3,a2=2.1,b2=5.3,c=0.22;
y1=a1*x+b1;
y2=a1*x^2+b2*x+c;
return(y2>y1);};

?can you say what is wrong?

Parents
  • float comppoly(x)
    {
      float y1, y2;
      float a1=0.1, b1=0.3, a2=2.1, b2=5.3, c=0.22;
    
      y1 = (a1 * x)   +  b1;
      y2 = (a1 * x^2) + (b2 * x) + c;
    
      return(y2 > y1);
    }
    
    or (more math):
    
    float comppoly(x)
    {
      float y1, y2;
      float a1=0.1, b1=0.3, a2=2.1, b2=5.3, c=0.22;
    
      y1 =              (a1 * x) + b1;
      y2 = (a1 * x^2) + (b2 * x) + c;
    
      return(y2 > y1);
    }
    
    or (simple):
    float comppoly(x)
    {
      float y1, y2;
      float a1=0.1, b1=0.3, a2=2.1, b2=5.3, c=0.22;
    
      y1 = a1 * x   + b1;
      y2 = a1 * x^2 + b2 * x + c;
    
      return(y2 > y1);
    }
    

    I made it readable and corrected a minor error :-)
    Breakets are not only for compiling, they also increase the readabillity.

    .
    BR,
    /th.

Reply
  • float comppoly(x)
    {
      float y1, y2;
      float a1=0.1, b1=0.3, a2=2.1, b2=5.3, c=0.22;
    
      y1 = (a1 * x)   +  b1;
      y2 = (a1 * x^2) + (b2 * x) + c;
    
      return(y2 > y1);
    }
    
    or (more math):
    
    float comppoly(x)
    {
      float y1, y2;
      float a1=0.1, b1=0.3, a2=2.1, b2=5.3, c=0.22;
    
      y1 =              (a1 * x) + b1;
      y2 = (a1 * x^2) + (b2 * x) + c;
    
      return(y2 > y1);
    }
    
    or (simple):
    float comppoly(x)
    {
      float y1, y2;
      float a1=0.1, b1=0.3, a2=2.1, b2=5.3, c=0.22;
    
      y1 = a1 * x   + b1;
      y2 = a1 * x^2 + b2 * x + c;
    
      return(y2 > y1);
    }
    

    I made it readable and corrected a minor error :-)
    Breakets are not only for compiling, they also increase the readabillity.

    .
    BR,
    /th.

Children