Header Ad

C++ program to display a stop watch on screen for 2 minutes

In this post, we will write a C++ program to display a stopwatch on the screen for 2 minutes with applicable program code and output.

C++ program to display a stop watch on screen for 2 minutes


C++ program to display a stopwatch on screen for 2 minutes.

#include<iostream>
#include<conio.h>
#include<windows.h>

BOOL gotoxy(const WORD x, const WORD y) {
    COORD xy;
    xy.X = x;
    xy.Y = y;
    return SetConsoleCursorPosition(GetStdHandle(STD_OUTPUT_HANDLE), xy);
}

int main()
{
    system("cls");
    int i,j,k,res,min,sec;
    char ch;
    min = 0;

    for(k=0; k<2; k++)
    {
        sec = 0;
        for(j=0;j<=59;j++)
            for(i=0;i<=5850;i++)
            {
                gotoxy(20,15);
                if(i==5850)
                    sec = sec + 1;
                if(sec == 60)
                    min = min + 1;

                std::cout<<min<<" : "<<sec<<" : "<<i;
            }
    }

    getch();
    return 0;
}


Output

C++ program to display a stop watch on screen for 2 minutes



Post a Comment

0 Comments