用C++如果实现奥运倒计时?

来源:百度知道 编辑:UC知道 时间:2024/05/15 09:15:35
用C++如果实现奥运倒计时?

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

void wait ( int seconds )
{
clock_t endwait;
endwait = clock () + seconds * CLK_TCK ;
while (clock() < endwait) {}
}

void main(){
time_t rawtime;
struct tm * target_time;
int d,h,m,s;
int k=0;
long double dif,r;
time_t now,t_end; // in sec

/* get current timeinfo and modify it to the user's choice */
time ( &rawtime );
target_time = localtime ( &rawtime );

// time struc and to time_t
target_time->tm_year = 2008 - 1900; //year - 1900
target_time->tm_mon= 8 - 1; // month - 1
target_time->tm_mday = 8 ; // day
target_time->tm_hour = 8 ; // hour
target_time->tm_min = 1 ;
target_time->tm_sec = 1 ;
t_end = mktime (target_time);
// printf("%s ",ctime(&t_end)); //print and check

while (k &