I'm writting a simple program which prints something at a fixed interval of time. Say, “|” every second for 10 seconds. The way I figured doing it is to write a function that pauses for a fixed amount of time. And the printing part is in a for loop in main().
It works fine except for any non-integer intervals because of the limitations of time_t. A simplified excerpt of the code is included.
Can anyone please help me improve this code so that the function can work on floating points too? I realize that this might have to be machine dependent but a simple code will be much appreciated.
cin is undefined. I assume you meant the standard in. You forgot to #include <iostream>
Also, please do put the open bracket beneath the functions and for loops, it (imo) makes it much more readable as it makes it more obvious where the block starts.
Here's your new code.
Mind you, it's very tedious to use double. Use milliseconds instead.