闹钟未提供预期的C输出

问题描述

我目前正在为学校用C语言制作闹钟,但是我有两个主要问题:

1:警报的printf永远不会打印。

2:如果我写的s应该大于50,则它开始打印负值,或者它变为0并在到达警报之前整整24小时(如果我写一个值而不是a,b和c,您将在下面看到:

我在下面的代码中打印了我期望的输出

#include <stdio.h>

int main () {

    int h,m,s;
    int a,b,c;

    printf("Please write a time in the following format: hh:mm:ss \n");
    scanf("%d%d%d",&h,&m,&s);

    
    printf("Please state your alarm in the following format: hh:mm:ss ");
    scanf("%d%d%d \n",&a,&b,&c);
    
    
    start: ;
    for (h; h<24; h++) {
        for (m; m<60; m++) {
            for (s; s<60; s++) {
                if (a==h && b==m && c==s) {
                    printf("Alarm");
                    return 0;
                } else {
                    printf("%d:%d:%d \n",h,s);
                }
            }
            s=0;
        }
        m=0;
    }
    h=0;
    goto start;
}

预期输出

Please write a time in the following format: hh:mm:ss
23:50:51
Please state your alarm in the following format: hh:mm:ss
23:50:54

23:50:52
23:50:53
ALARM

任何帮助将不胜感激。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)