如何解决闹钟未提供预期的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 举报,一经查实,本站将立刻删除。