Friday, February 13, 2015

C C Program to Create a Digital Stopwatch

C/C++ Program to Create a Digital Stopwatch

Hello friends, this is a simple program to create a digital stopwatch. I am sure that even a beginner can understand it very easily. I have written this in c++, so to use it c just change all cout statements with corresponding printf statements. I hope you understand what i want to say. If you have any kind of problem in doing this then let me know by commenting below, i will try my best to help you. So just try this and share your experience with me.

Also Read: C++ Program to create an Analog Clock
Also Read: C++ Hotel Management Project


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

int h=0,m=0,s=0,ms=0;
char ch=p;

void main()
{
void watch();
watch();

while(1)
{
if(kbhit())
ch=getch();
if(ch==s||ch==S)
break;
if(ch==e||ch==E)
exit(0);
}

while(1)
{
watch();
delay(10);

if(kbhit())
ch=getch();

if(ch==r||ch==R)
{
h=m=s=ms=0;
watch();

while(1)
{
if(kbhit())
ch=getch();
if(ch==s||ch==S)
break;
if(ch==e||ch==E)
exit(0);
}
}
else
if(ch==p||ch==P)
while(1)
{
if(kbhit())
ch=getch();
if(ch==s||ch==S)
break;
if(ch==e||ch==E)
exit(0);
if(ch==r||ch==R)
{
ch=c;
h=m=s=ms=0;
watch();
}
}
else
if(ch==e||ch==E)
exit(0);

if(ms!=99)
ms++;
else
{
ms=0;
if(s!=59)
s++;
else
{
s=0;
if(m!=59)
m++;
else
{
m=0;
h++;
}
}
}
}
}


void watch()
{
clrscr();
cout<<"




#############";

cout<<"
# Stopwatch #";

cout<<"
#############";

cout<<"

 "<<h<<":"<<m<<":"<<s<<":"<<ms;


cout<<"








Press Key";

cout<<"
---------";

cout<<"
s -> Start";

cout<<"
p -> Pause";

cout<<"
r -> Reset";

cout<<"
e -> Exit";

}

No comments:

Post a Comment

Note: Only a member of this blog may post a comment.