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<<“nnnnntttt#############”;
cout<<“ntttt# Stopwatch #”;
cout<<“ntttt#############”;
cout<<“nntttt  “<<h<<“:”<<m<<“:”<<s<<“:”<<ms;

cout<<“nnnnnnnnntttttttPress Key”;
cout<<“nttttttt———“;
cout<<“nttttttts -> Start”;
cout<<“ntttttttp -> Pause”;
cout<<“ntttttttr -> Reset”;
cout<<“nttttttte -> Exit”;
}

10 thoughts on “C/C++ Program to Create a Digital Stopwatch

  1. Vishnu Agarwal

    my code is not compiling it is showing fetal error unknown iostream.h directory .I am compiling it in codeblocks and in .c file..please help me out with it….

    Reply
  2. USMAN HAIDER

    it's also not working in dev-c++ and after syntax checking following msgs appears:
    error: '::main' must return 'int'

    In function 'int main()':
    error: 'delay' was not declared in this scope
    In function 'void watch()':
    error: 'clrscr' was not declared in this scope
    error: 'cout' was not declared in this scope
    note: suggested alternative:

    Reply
  3. Sudeshna

    I am a beginner and I am not getting the role of kbhit function

    Reply
  4. Avinash

    This code doesn’t works in c++ 11 standards .
    Mostly if you are you using codeblocks or mono develop

    Reply

Leave a Reply

Your email address will not be published. Required fields are marked *