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”;
}
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….
u have to compile using .cpp while using iostream.h
What means "void" in c++?
void means that the main() function will not return any value.
It means function is not gonna retunr anything
Can you please give me an explication on how that’s program run.
y not use setw()?
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:
conio.h is not the Part of the c++ so that’s why it is not present in Dev-c++ use system(“cls”) instead of the clrscr and and add using namespace std; after library files also add windows.h library for system(“cls”) remove .h from iostream just use #include
Awesome projects you have designed 🙂
I am a beginner and I am not getting the role of kbhit function
This code doesn’t works in c++ 11 standards .
Mostly if you are you using codeblocks or mono develop
Wrong code. Doesn’t work.
not working at all
Sir plz help me to write programme on stopwatch using dos