alarm.cpp

来自「是100篇C++编程实例,以源代码形式,帮助你学习C」· C++ 代码 · 共 43 行

CPP
43
字号
#include<stdio.h>
#include<dos.h>
#include<conio.h>

int main(void)
{
   int HOUR=0,MINUTE=0,SECOND=0;
   struct  time T;

   clrscr();
   textcolor(12);
   gettime(&T);
   gotoxy(10,5);
   cprintf("The current time is: %2d:%02d:%02d\n",
		T.ti_hour, T.ti_min, T.ti_sec);
   textcolor(11);
   gotoxy(10,7);
   cprintf("Input the alarm time please!");
   textcolor(YELLOW);
   gotoxy(10,9);
   cprintf("The hour(0-23):");
   scanf("%d",&HOUR);
   gotoxy(10,11);
   cprintf("The minute(0-59):");
   scanf("%d",&MINUTE);
   gotoxy(10,13);
   cprintf("The second(0-59):");
   scanf("%d",&SECOND);

   while((HOUR*3600+MINUTE*60+SECOND-(T.ti_hour*3600+T.ti_min*60+T.ti_sec))>0)
   {
	gettime(&T);
   }
   while(!kbhit())
	sound(440);
   nosound();
   getch();
   gotoxy(10,15);
   textcolor(WHITE);
   cprintf("Press any key to exit... ...");
   getch();
   return 0;
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?