Click here to Skip to main content
13,449,346 members (45,985 online)
Click here to Skip to main content
Add your own
alternative version

Tagged as


3 bookmarked
Posted 18 May 2010

A count down timer in c.

, 10 Jun 2010
Rate this:
Please Sign up or sign in to vote.
set the variable count_down_time_in_secs in seconds for desired count down time.The Code is self explanatory.1 minute = 60 secs5 minutes = 60x5 secs30 minutes =60x30 secs1 hour = 60x60 secs#include #include int main (){ unsigned int...
set the variable count_down_time_in_secs in seconds for desired count down time.
The Code is self explanatory.

1 minute = 60 secs
5 minutes = 60x5 secs
30 minutes =60x30 secs
1 hour = 60x60 secs

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

int main ()
	unsigned int x_hours=0;
	unsigned int x_minutes=0;
	unsigned int x_seconds=0;
	unsigned int x_milliseconds=0;
	unsigned int totaltime=0,count_down_time_in_secs=0,time_left=0;

	clock_t x_startTime,x_countTime;
	count_down_time_in_secs=10;  // 1 minute is 60, 1 hour is 3600

    x_startTime=clock();  // start clock
    time_left=count_down_time_in_secs-x_seconds;   // update timer

	while (time_left>0) 
		x_countTime=clock(); // update timer difference


		time_left=count_down_time_in_secs-x_seconds; // subtract to get difference 

		printf( "\nYou have %d seconds left ( %d ) count down timer by TopCoder 


	printf( "\n\n\nTime's out\n\n\n");

return 0;




This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


About the Author

About me:
I attended programming college and I have a degree in three most famous and successful programming languages. C/C++, Visual Basic and Java. So i know i can code. And there is a diploma hanging on my wall to prove it.
I am a professional, I am paid tons of cash to teach or do software development. I am roughly 30 years old .

I hold lectures in programming. I have also coached students in C++, Java and Visual basic.

In my spare time i do enjoy developing computer games, and i am developing a rather simple flight simulator game
in the c++ programming language using the openGL graphics libray.

I've written hundreds of thousands of code syntax lines for small simple applications and games.

You may also be interested in...

Comments and Discussions

QuestionClocks_per_seconds Pin
Xu-Ming Koh5-Aug-15 19:09
memberXu-Ming Koh5-Aug-15 19:09 
Questionu better read it Pin
Member 103232338-Oct-13 4:20
memberMember 103232338-Oct-13 4:20 
Questionmiliseconds? Pin
krishna_srivastava11-Mar-13 1:12
memberkrishna_srivastava11-Mar-13 1:12 
GeneralI have to agree to SledgeHammer, this is a good example for ... Pin
imagiro19-Jun-10 0:12
memberimagiro19-Jun-10 0:12 
GeneralReason for my vote of 1 This is useless. No cmd line params,... Pin
SledgeHammer0118-May-10 16:04
memberSledgeHammer0118-May-10 16:04 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

Permalink | Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.180318.3 | Last Updated 10 Jun 2010
Article Copyright 2010 by Software_Developer
Everything else Copyright © CodeProject, 1999-2018
Layout: fixed | fluid