Jump to content
  • Advertisement

Archived

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

Zorbfish

A few questions

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

1. timeGetTime(), How do I use it??? I want to use it to make a game timer but I recieve undeclared identifier errors when I compile 2. How would probability work in C++? For example if I wanted there to be a 30% chance of something happening or not.

Share this post


Link to post
Share on other sites
Advertisement
timeGetTime() i think you get if you #include <windows.h>. I think many will argue that there are better timers than this one, though.

For probability you could use something like this:

if((rand() % 100) <= 30) ThenDoThis();


[edited by - CWizard on September 1, 2002 6:38:39 PM]

Share this post


Link to post
Share on other sites
timeGetTime is actually not a bad method if you don''t mind EXE size. You''ll need to include mmsystem.h and then link winmm.lib

There are dozens of threads on random numbers. A cheap way to do a 30% chance requires you to include stdlib.h and time.h and then use this code:

//call this once at the outset of your program:
srand(time(0)); // I think this''ll work. Lemme know if it doesn''t.

//execute this each time you need a chance:
bool WillHappen = (rand()/(double)RAND_MAX) <= 0.3;

Peace,
ZE.

//email me.//zealouselixir software.//msdn.//n00biez.//
miscellaneous links

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!