Hey, I've been working on an alarm clock that uses three while loops. Problem is that only the last one works properly. The program takes in two inputs, current time and alarm time (both in HHMMSS). Those get split into hours, minutes and seconds, which the loops then use.

Correct output:

23:59:58
23:59:59
00:00:00
00:00:01
00:00:02
ALARM

Incorrect output:

20:14:55
20:14:56
20:14:57
20:14:58
20:14:59
20:15:00

Here're my three while loops:

Code:
while(present_hour != alarm_hour){if(present_hour == alarm_hour && present_minute == alarm_minute && present_second == alarm_second){
            printf("ALARM");
        }
        else{
            if(present_second < 60){
                present_second++;
                
                if(present_second == 60) {
                    present_second = 0;
                    present_minute++;
                }
                if(present_minute == 60){
                    present_minute = 0 ;
                    present_hour++;
                }
                if(present_hour == 24){
                    present_hour = 0;
                }
                printf("%02d-%02d-%02d \n", present_hour, present_minute, present_second);
                    
            }
        }
    }
    while(present_minute != alarm_minute){
        if(present_hour == alarm_hour && present_minute == alarm_minute && present_second == alarm_second){
            printf("ALARM");
        }
        else{
            if(present_second < 60){
                present_second++;
            }
                
                if(present_second == 60){
                    present_second = 0;
                    present_minute++;
                }
                printf("%02d_%02d_%02d \n", present_hour, present_minute, present_second);
        }    
    }
    while(present_second != alarm_second){
        present_second++;
        if(present_hour == alarm_hour && present_minute == alarm_minute && present_second == alarm_second){
            printf("ALARM");
        }
        else{
        printf("%02d:%02d:%02d \n", present_hour, present_minute, present_second);
        }
    }
I really don't get why only the last loop prints "ALARM" instead of the alarm time. Since "ALARM" being printed requires the if statement being true, I could see that being the problem. But if it works in the last loop, why doesn't it work for the other two?

I've been staring at these loops for quite some time, to no avail. Any pointers or hints would be greatly appreciated! I hope I've explained myself well enough, but feel free to ask if something is weird or confusing.

Thanks in advance!