• Advertisement

Archived

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

Quick problem, quick answer, please..!

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