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
 

0 comments: