A few questions
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.
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]
For probability you could use something like this:
if((rand() % 100) <= 30) ThenDoThis();
[edited by - CWizard on September 1, 2002 6:38:39 PM]
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
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
[twitter]warrenm[/twitter]
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement