Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Goblin

Quick problem, quick answer, please..!

This topic is 6511 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

  
struct SECTION
{
     float top,bottom,left,right;
};

SECTION newSect()
{
     SECTION newSection;

     newSection.top = -0.7 + ( (rand() % 400) / 1000 );
     // should generate a random number from -0.7 to -0.3

     // code is continued for bottom, left, and right...

     return (newSection);
}

// Later, in the main game loop...

SECTION tunnel_section = newSect();
printf("%f",tunnel_section.top);
  
... and it gives me -0.700000 every single time. I assume this is some sort of problem with converting the right side of the equation to a float, but I''m really not sure how to make it act correctly. Uhh... how? Thanks! ----------------- The Goblin ----------------- "Oh, God..." "Yes?" <- My Response

Share this post


Link to post
Share on other sites
Advertisement
*grin*

Thanks!

Amazingly, I was actually able to insert the (float) typecast into enough random places to come out with that exact answer, but I appreciate it, thanks!

Learn something new every day.

I wonder how I would prevent the answer from going more than two decimal places...

-----------------
The Goblin
-----------------
"Oh, God..."
"Yes?" <- My Response

Share this post


Link to post
Share on other sites

  • 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!