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?
Oh, yeah.
I do not see the right answer
?I do not understand you? But I now have my answer. \goodbye
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.
It wouldn't hurt giving the input parameter x a data type too.
LOL, didn't see that (just looked at the code) :-)
My ChrystalBall assumes:
float comppoly(float 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); }
So, I guess that the compiler warns, and assumes int. That of course gives the wrong answer if fed with float ...
Hah. Now it won't even compile (on a sane compiler). Not exactly a big improvement, is it?
:->
x^2 is a bit problematic when x is a float.
But then again - it is a bit problematic when x is an int too...