我正在为计时器编写代码,到目前为止,如果我按1计时器开始运行,但是当我按2停止/暂停计时器时它不会停止,有人可以帮忙吗?
#include <stdio.h>#include <stdlib.h>
#include <windows.h>
#define TRUE 1
int main(void) {
int hour = 0, min = 0, sec = 0;
int num1;
int num2;
printf("Press 1 to start the timer");
scanf_s("%d", &num1);
if (num1 == 1) {
while (TRUE) {
printf("\r %2d : %2d : %2d", hour, min, sec, "\n");
printf("\t\t\t""Press 2 to stop the timer");
sec++;
Sleep(1000);
if (sec == 59) {
min++;
sec = 0;
}
if (min == 59) {
hour++;
min = 0;
sec = 0;
}
if (scanf_s("&s", &num2)) {
(num2 == 2);
break;
}
}
}
return 0;
}