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--) {
			printf ("\r%i : %i", minute, second); 
             int g;
               for (g = 0; g < NumberOfItems; NumberOfItems++) {
     		     if (minute = TimeToAlarm[g]) {

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


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.



Recommended Answers

All 4 Replies

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

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?



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".


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!


Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.