先输入现在时间(比如1h2m30s),回车
再输入喝咖啡时间,回车
然后等着就行了!!请看:
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#define INTERVAL 20
void sleep( long wait )
{
long goal;
goal = wait + clock();
while( goal > clock() );
}
main()
{
int now,begin,goal,t;
int h,m,s;
int eh,em,es;
scanf("%dh%dm%ds",&h,&m,&s);
scanf("%dh%dm%ds",&eh,&em,&es);
goal=eh*60*60+em*60+es;
while(1)
{
sleep(1000);
system("cls");
s++;if(s>=60){s=00;m++;}
if(m>=60){m=00;h++;}
printf("%dh%dm%ds",h,m,s);
t=h*60*60+m*60+s;
if(goal-t<=INTERVAL)printf("喝一杯咖啡!\n");
if(goal-t<=0){printf("Time out!\n");exit(0);}
}
}
温馨提示:答案为网友推荐,仅供参考