A countdown timer in c++

piyush gandhi -2 Tallied Votes 11K Views Share

here is a wonderful short program to try out!

A COUNTDOWN TIMER

#include<iostream.h>
#include<conio.h>

main()
{


int m,s;

cout<<"\n\n\n\t\t\t     A COUNTDOWN TIMER \n";

cout<<enter time in MINUTES here \t = \t";
cin>>m;

cout<<enter time in SECONDS here \t = \t";
cin>>s;




cout<<"\n\n\n\n\t press any key to start...!!!";

getch();
clrscr();


cout<<"\n\n\n\t\t\t     A COUNTDOWN TIMER \n";

cout<<"\n\n\n\t\t TIME REMAINIG \n\n";

cout<<"\t mins: \t\t seconds: ";

for(int min=m;min>0;min--)
{
for(int sec=59;sec>=;sec--)
{

sleep(1);

cout<<"\r"<<min<<"\t"<<sec;

}

}

for(int rem=s;rem>=0;rem--)
{
cout<<"\r"<<min<<"\t"<<rem;
}

cout<<"\n\n  ENDED ";

return 0;

}               /* end of program */



/* developed by piyush */
Ene Uran 638 Posting Virtuoso

Why are you using the C snippets for a C++ snippet? There is a difference between the two old languages.

vegaseat 1,735 DaniWeb's Hypocrite Team Colleague

Thanks for moving it to C++, whoever did it.

ShawnCplus 456 Code Monkey Team Colleague

It should be int main(void) and lines 12 and 15 will cause errors due to a missing " at the beginning of the string.

m99marine 0 Newbie Poster

This is a much better program than the one above.

#include <iostream>
#include <stdio.h>
#include <conio.h>
#include <windows.h>


 using namespace std;

int main()

{

	 int m, s,h;

	 cout << "A COUNTDOWN TIMER " << endl;
	 cout << "enter time in hours here" << endl;
	 cin >> h;
	 cout << "enter time in minutes here " << endl;
	 cin >> m;

	 cout << "enter im in seconds here" << endl;
	 cin >> s;

	 cout << "Press any key to start" << endl;

	 cout << " A COUNTDOWN TIMER" << endl;
	 cout << "time remaining" << endl;
	 cout << "hours : " << h << "mins : " << m << " secs : " << s << endl;

	 for (int hour = h; hour >= 0; hour--)
	 {
		 for (int min = m; min >= 0 ; min--)
		 {
			 if ( min == 0 && h > 0)
				 m = 59;
			for (int sec = s; sec >= 0; sec--)
			{
				if ( sec == 0 )
					s = 59;
				Sleep(1000);
				system("cls");
				cout << hour << " :hours " << min << " :mins " << sec << " :secs"  << endl;
			}
		 }
	 }
	 
	Sleep(1000);
	 cout << "THE END" << endl;
	 

	return 0;
DubyStev 0 Newbie Poster

here is a wonderful short program to try out!

Which header file will I use to call the sleep function bcos I am using DEV-cpp

Ricky65 0 Newbie Poster

here is a wonderful short program to try out!

Which header file will I use to call the sleep function bcos I am using DEV-cpp

Here is the documentation you need for the Win32 "Sleep" function

http://msdn.microsoft.com/en-us/library/ms686298%28VS.85%29.aspx

KarmaHunter 0 Newbie Poster

This is a much better program than the one above.
Although an old post, your code is missing a last "}"

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.