倒计时器c语言源程序

能时分,秒倒计时,到时会发声音信号,有键盘,能显示。
帮忙写一个

#include <stdio.h>
#include <time.h>

struct Clock
{
int sec,min,hour;
void tick();
void show();
void run();
void set(int h,int m,int s);
};

void Clock::tick()
{
long t=time(NULL);
while(t==time(NULL));
if(--sec<0){
sec=59;
if(--min<0){
min=59;
--hour;
}
}
}

void Clock::show()
{
printf("\r");
if(hour<10)
printf("0");
printf("%d:",hour);
if(min<10)
printf("0");
printf("%d:",min);
if(sec<10)
printf("0");
printf("%d",sec);
}

void Clock::run()
{
while(sec!=0||min!=0||hour!=0){
tick();
show();
}
}

void Clock::set(int h,int m,int s)
{
hour=h;
min=m;
sec=s;
}

int main()
{
int s,m,h;
printf("请输入时间(hhmmss):");
scanf("%d%d%d",&h,&m,&s);
Clock c;
c.set(h,m,s);
c.run();
printf("time is over!!!\a");
}
温馨提示:答案为网友推荐,仅供参考

相关了解……

你可能感兴趣的内容

本站内容来自于网友发表,不代表本站立场,仅表示其个人看法,不对其真实性、正确性、有效性作任何的担保
相关事宜请发邮件给我们
© 非常风气网