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

Do you see a problem with if (minute = TimeToAlarm[g]) ? Is the comparison correct?

Hi WaltP,

Thanks for getting back. I am not sure as to any other way to make a comparison. This is the only way that I am trying at the moment. Do you have alternative methods?

Regards,

rjani1

Look up Comparison operators in your book. It's best to check your book when someone makes a comment -- however cryptic -- and not just post back "I don't know".

WaltP,

Problem solved. Please try to answer the question as directly as you can; no matter how "cryptic" you are feeling. I could do without the aggro!

rjani1

This question has already been answered. Start a new discussion instead.