
c语言秒表程序
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”;
}
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”;
}
翻译自: https://www.thecrazyprogrammer.com/2013/06/cc-program-to-create-digital-stopwatch.html
c语言秒表程序