Dear All,
I am trying to code a multistage timer which prints out a line of text. The timer countdowns from a certain point in time and then prints out a line at times defined in an array. The array is sizable so there is no fixed length. The user can have as many stages as they require.
The code is below:
for (minute = time; minute > -1; minute--) {
for (second = 59; second > -1; second--) {
sleep(1);
printf ("\r%i : %i", minute, second);
fflush(stdout);
}
int g;
for (g = 0; g < NumberOfItems; NumberOfItems++) {
if (minute = TimeToAlarm[g]) {
printf("Alarm\n");
}
}
}
During operation, say that want an alarm at 11 minutes and then at 10 minutest, the array would consist of TimeToAlarm[12, 11, 10], So the time is initialised from the beginning as the highest values and then the timer
counts down. Once it reaches 11 it should (in my opinion) print the "Alarm" statement which it does but three times.
I reckon its to do with the
for
loop but am not sure how else to code it so that it appears once for the
last two remaining times (11 and 10).
Any tips would be greatly appreciated.
Regards,
rjani1