create Timer in C++

नीचे दिए गए program में, while-loop, for-loop और if-else statement का प्रयोग किया गया है यहाँ पर एक pre -defined , _setcursortype() का use किया गया है जो mouse cursor से related होता है –

_setcursortype();

इस program का syntax नीचे दिया गया है –

while(j>0)
 { 
   for(.......)
    {
       if(i<10)
         .........//print single type of digit in timer 

       else if(i>9)
          ........//print two type of digit in timer
       if(j==0) && i==19)
         {
          .........//display last message 

         }
     } j--;
   }

program में user -input एक minute-type value की तरह व्यवहार करेगा-

#include<iostream.h>
#include<conio.h>
#include<dos.h>
#include<string.h> // strcpy
#include<stdlib.h> //atoi, exit()
#include<stdio.h> // remove

  void main()
  {
     clrscr();
     int n;
     char c;

    cout<<"Enter the number(minute) to be start counting: ";
    cin>>n;

    int j=n;
    _setcursortype(0); //_setcursortype(NOCURSOR); also work

    while(j>=0)
     {
       for(int i=0;i<20;i++)
        {
           cout<<"\n\n\n\n\n"<<setw(35)<<"\n";
           if(i<10)
           {
              c = '0';
              cout<<"\t\t\t 0"<<j<<" : "<<c<<i; 
           }
          else if(i>9) 
          cout<<"\t\t\t 0"<<j<<" : "<<i;

          cout<<"\n"<<setw(35)<<"%%%%%%%%%%%\n";
          delay(100);

          clrscr();

          if(j==0&&i==19) 
           {
               cout<<"\n\n\n\n\t\ttime up....";
           }
        }j--;
     }
   getch();
 }

OUTPUT

OUTPUT:- 
Enter the number(minute) to be start counting: 2 

   %%%%%%%%%%% 
     02:00 
   %%%%%%%%%%%


Related exercises,

Leave a Reply

Your email address will not be published.