Why is this sloppy code?

Just watched a short video on creating a timer in c++. It looks a decent program to a beginner but i'm hoping a more experienced coder can tell me why it is wrong.

So far this forum has taught me when writing c++ you should be killed for using 'system' commands, and something to do with making variables public.

The owner of the code (http://www.youtube.com/user/Strupe321) says that this is a bad way to write a timer and should never be used, here is the video.

http://www.youtube.com/watch?v=AZI2D-HEe3M

I'm guessing it's something to do with the sleep command?
The variable named milliseconds is storing deciseconds, not milliseconds. It is not very accurate because Sleep(100) can take more time than 100 milliseconds, and it doesn't take into account that the program code takes time to run, so the timer will run slightly too slow.
Last edited on
so, the faster the computer, the more accurate the timer is? (as in the code will process faster)
Yes, but there are a lot of other things that also matters like the CPU has a lot of other processes running, etc.
Topic archived. No new replies allowed.