I have a little trouble in the display of heights for my program. This is what i wrote:
if (0 < LaserX < 161) {
LaserX = LaserX/n;
LaserY = LaserY/n;
sprintf(LaserMID, "%.1f, %.1f",开发者_开发百科 LaserX, LaserY);
ShowCo->Text = LaserMID;
}
else { ShowCo->Text = 0; }
So basically it will show the height value when I have LaserX between 0 to 161, and anything out of that it shows 0. But in my case, when the LaserX value is out of the range, it shows me -NAN instead. What is -NAN?! How do i get rid of it? Please advice, thnx.
Below condition is not what you want,
if (0 < LaserX < 161) // evaluated from left thus always true (which is unwanted)
You can change it to,
if (0 < LaserX && LaserX < 161)
It precisely means that LaserX
is greater than 0
and less than 161
.
Edit: NaN = Not a Number.
0 < LaserX < 161
Is wrong, as it is same as
(0 < LaserX) < 161
Which is always true as (0 < LaserX)
goes to 1 or 0
You need
0 < LaserX && LaserX < 161
P.S.: Don't use Turbo C++... It is dead, outdated and should not be used
NAN - not a number.
Change condition as in answers above. And problem will disappear.
精彩评论