Originally Posted by
SeriousTyro
so if the user sets the program length to 500 secs and sets the interval to 400 secs, I would not end the program at the right time.
This is where you use counters... rather than setting a single time increment of 500 seconds, set a time increment of 1 second and count to 500 before firing the event.
Code:
int interval = 500;
int ticks = 0;
While( ticks < interval)
{ sleep(1000); // assuming milliseconds
// do "while waiting" stuff here
++ ticks; }
// do timed event stuff here
If there is a concern about two intervals needing to be in a specific relationship, such as the program has to run long enough for at least one event to occur... then you check the values entered and adjust accordingly....
Code:
If (interval > duration)
duration = interval;