timer in c++
C++
// CPP program to create a timer
#include <iomanip>
#include <iostream>
#include <stdlib.h>
#include <unistd.h>
using namespace std;
// hours, minutes, seconds of timer
int hours = 0;
int minutes = 0;
int seconds = 0;
// function to display the timer
void displayClock()
{
// system call to clear the screen
system("clear");
cout << setfill(' ') << setw(55) << " TIMER \n";
cout << setfill(' ') << setw(55) << " --------------------------\n";
cout << setfill(' ') << setw(29);
cout << "| " << setfill('0') << setw(2) << hours << " hrs | ";
cout << setfill('0') << setw(2) << minutes << " min | ";
cout << setfill('0') << setw(2) << seconds << " sec |" << endl;
cout << setfill(' ') << setw(55) << " --------------------------\n";
}
void timer()
{
// infinte loop because timer will keep
// counting. To kill the process press
// Ctrl+D. If it does not work ask
// ubuntu for other ways.
while (true) {
// display the timer
displayClock();
// sleep system call to sleep
// for 1 second
sleep(1);
// increment seconds
seconds++;
// if seconds reaches 60
if (seconds == 60) {
// increment minutes
minutes++;
// if minutes reaches 60
if (minutes == 60) {
// increment hours
hours++;
minutes = 0;
}
seconds = 0;
}
}
}
// Driver Code
int main()
{
// start timer from 00:00:00
timer();
return 0;
}
Also in C++:
- Title
- binary tree search
- Category
- C++
- Title
- inconsequential meaning
- Category
- C++
- Title
- convert string to stream c++
- Category
- C++
- Title
- c++ vector pop_back
- Category
- C++
- Title
- c++ try
- Category
- C++
- Title
- map arduino
- Category
- C++
- Title
- what is time complexity of insertion sort
- Category
- C++
- Title
- modulo c++
- Category
- C++
- Title
- delete a double pointer c++
- Category
- C++
- Title
- make an x using asterisk c++
- Category
- C++
- Title
- c++ files
- Category
- C++
- Title
- how to pass an object by reference in c++
- Category
- C++
- Title
- c++ compare char
- Category
- C++
- Title
- maximum subarray sum equal with K in c++
- Category
- C++
- Title
- lambda operator in c++
- Category
- C++
- Title
- c++ while true
- Category
- C++
- Title
- cin.fail()
- Category
- C++
- Title
- how to execute c++ program in cmd
- Category
- C++
- Title
- what does map.count() return in c++
- Category
- C++
- Title
- heap in cpp stl
- Category
- C++
- Title
- pointer related problems dangling/wild pointers c++
- Category
- C++
- Title
- vector pop back
- Category
- C++
- Title
- How to find the kth smallest number in cinstant space
- Category
- C++
- Title
- how the theam are store in database
- Category
- C++
- Title
- c++ code to print hello world
- Category
- C++
- Title
- class in c++
- Category
- C++
- Title
- differentialble programming
- Category
- C++
- Title
- root to leaf path print
- Category
- C++
- Title
- how to convert string into number
- Category
- C++
- Title
- for c++
- Category
- C++
- Title
- string to upper c++
- Category
- C++
- Title
- pointers in cpp
- Category
- C++
- Title
- time function c++
- Category
- C++
- Title
- c++ ros publisher
- Category
- C++
- Title
- substr in c++
- Category
- C++
- Title
- bitset c++
- Category
- C++
- Title
- min in vector c++
- Category
- C++
- Title
- substr c++
- Category
- C++
- Title
- iterative preorder traversal
- Category
- C++
- Title
- error: ‘memset’ was not declared in this scope in cpp
- Category
- C++
- Title
- traverse a map
- Category
- C++
- Title
- c++ code 2d block
- Category
- C++
- Title
- max three values c++
- Category
- C++
- Title
- declare vectors c++
- Category
- C++
- Title
- find in string c++
- Category
- C++
- Title
- iterate 2d array c++
- Category
- C++
- Title
- range based for loop c++
- Category
- C++
- Title
- c++ char if
- Category
- C++
- Title
- % operator in c++
- Category
- C++
- Title
- initialize 3d vector c++
- Category
- C++
- Title
- random number generator c++
- Category
- C++
- Title
- file format not recognized treating as linker script c++
- Category
- C++
- Title
- how to have a queue as a parameter in c++
- Category
- C++
- Title
- stringstream in c++
- Category
- C++
- Title
- c++ overload operator
- Category
- C++
- Title
- ue4 c++ enum
- Category
- C++
- Title
- 2d vector
- Category
- C++
- Title
- C++ and endl
- Category
- C++
- Title
- c++ switch
- Category
- C++
- Title
- c++ function return pointer to itself
- Category
- C++
- Title
- print matrix c++
- Category
- C++
- Title
- cout console
- Category
- C++
- Title
- compile c++ linux
- Category
- C++
- Title
- how to concatinate two strings in c++
- Category
- C++
- Title
- runtime array size c++
- Category
- C++
- Title
- sum of integer in array c++
- Category
- C++
- Title
- arrays in C++
- Category
- C++
- Title
- c++ excel cell blank cells
- Category
- C++
- Title
- c++ declare char
- Category
- C++
- Title
- ceil c++;
- Category
- C++
- Title
- c++ sort
- Category
- C++
- Title
- c++ program how to let the user choose different game modes
- Category
- C++
- Title
- check if key exists in map c++
- Category
- C++
- Title
- string comparison in c++
- Category
- C++
- Title
- c++ function to find length of array
- Category
- C++
- Title
- c++ yes no question
- Category
- C++
- Title
- nan c++ example
- Category
- C++
- Title
- minmax_element c++
- Category
- C++
- Title
- c++ class method example
- Category
- C++
- Title
- fail() in c++
- Category
- C++
- Title
- c++ course
- Category
- C++
- Title
- worker class c++
- Category
- C++
- Title
- lambda c++
- Category
- C++
- Title
- how to make a switch case statement in c++
- Category
- C++
- Title
- c++ map find
- Category
- C++
- Title
- sort a pair using c++ stl
- Category
- C++
- Title
- char to string c++
- Category
- C++
- Title
- what is atoi in strinf
- Category
- C++
- Title
- C++ sfinae
- Category
- C++
- Title
- how to make a n*n 2d dynamic array in c++
- Category
- C++
- Title
- c++ over load oprator to print variable of clas
- Category
- C++
- Title
- *max_element in c++
- Category
- C++
- Title
- passing array to function c++ pointer
- Category
- C++
- Title
- findung the mode in c++
- Category
- C++
- Title
- unsorted array to bst
- Category
- C++
- Title
- tokenize string c++
- Category
- C++
- Title
- initialization list c++
- Category
- C++
- Title
- sieve of eratosthenes c++
- Category
- C++
- Title
- getch c++ library
- Category
- C++
- Title
- solve linear equations geeksforgeeks
- Category
- C++