Jump to content
  • Advertisement
Sign in to follow this  
Niddles

Why will this if statement not work?

This topic is 4558 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Once again ran into a problem that I can't figure out.. after I got the last one solved, I've been sitting here trying to figure this one out. Does anything look wrong with this function to you?
bool block::atBottom()
{
    if(x <= -0.9)
    {
        moveable = false;
        return true;
    }
    else
        return false;
}


I put in error checking message boxes before and after the if(x <= -0.9) it shows up before, but not inside the brackets. Why will this inequality not work? P.S. x is part of the block class, and so is moveable, if that variable matters in this situation, which it shouldn't. P.P.S It's probably something I'm going to feel stupid for, but hey, its 2:00 AM here.

Share this post


Link to post
Share on other sites
Advertisement
The <= makes me think you're counting on equality, which is a No-No when you're working with floating point numbers.

float a = 0.9 / 3.0;

if(a <= 0.3)
{
// This may not execute!
}

Put simply, to a computer, 0.9/3.0 may equal 0.9000000000243, even if it prints out as 0.9. For more, read this.

Share this post


Link to post
Share on other sites
I can't figure out how to print it out, it won't let me convert it from float to const char*, so I can pass it through MessageBox(). Hmmmm.

Share this post


Link to post
Share on other sites
If that is the case, then how can I tell my blocks when to stop on the board, when they reach the bottom?

Share this post


Link to post
Share on other sites
Quote:
Original post by Niddles
I can't figure out how to print it out, it won't let me convert it from float to const char*, so I can pass it through MessageBox(). Hmmmm.


Try formatting your message with sprintf().

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!