Showing posts with label digital timer simulation. Show all posts
Showing posts with label digital timer simulation. Show all posts

C++ Code Simulation The Timer in hh:mm:ss format

Leave a Comment
/*This code is for timer simulation Through C++ codes, initially the timer is set to 0:0:0 i.e, 0 hours , 0 minutes & 0 seconds, it updates its value every second, by the sleep(1000) function.*/

#include<iostream>
#include<Windows.h>    //for timing functions
using namespace std;

struct time{

    int hh,mm,ss;     //hh=hours, mm=minutes & ss=seconds
};

int main()
{
    time a;     //setting the initial count to zero
    a.hh = 0;
    a.mm = 0;
    a.ss = 0;

    for(int i = 0; i<24; i++)
    { //for 24 hour format
        if(a.hh == 23)
        {
            a.hh = 0;
        }

        for(int j = 0; j<60; j++)
        {
            if(a.mm == 59)
            {
                a.mm = 0;
            }

            for(int k = 0; k<60; k++)
            {
                if(a.ss == 59)
                {
                    a.ss = 0;
                }

                cout<<a.hh<<" : "<<a.mm<<" : "<<a.ss<<endl;
                a.ss++;
                Sleep(1000);   //For 1000 milliseconds or 1 second delay
                system("Cls");
            }
        a.mm++;

    }

        a.hh++;
    }

}


ScreenShots: 
C++ Code Simulation The Timer in hh:mm:ss format
 
Read More...

Digital Timer Simulation in C-Langauge(Turbo C++) using nested for loops, delay() and clrscr() fucntions.

Leave a Comment
#include<stdio.h>      //for standard input/output function
#include<conio.h>     //for console input/output related function
#include<time.h>      //for time related function
void main()
{
int sec,min,hour;
for(hour=0;sec<=24;hour++)
{
for(min=0;min<=60;min++)
{
for(sec=0;sec<=60;sec++)
gotoxy(12,50);
//To print the text at 12th coloum and 50th row of the screen textcolor(4+128);
//To set Red Color and Blink
cprintf("Timer Simulation By Shariq Khan,Press Any Key To Exit");
textcolor(2);
gotoxy(30,16);
cprintf("****************");
//To print *
gotoxy(35,18);
cprintf("H:M:S");
gotoxy(35,20);
cprintf("%d:%d:%d",hour,min,sec);
gotoxy(30,22);
cprintf("****************");
delay(1000);
//To halt the execution for 1000 miliseconds(1 sec)
if(kbhit()) //To check for any key pressed by user
exit(1);//if key is pressed then program is stopped
}
}
getche();
}
Read More...