In this tutorial, we will learn how to create a count down timer program in C++. To understand better, you may go through the following first.
The program takes the value to start the countdown and then reverse the countdown from there. The while loop is used to reverse the entered value.
Print Count Down Timer in C++
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 | #include <iostream> #include <Windows.h> using namespace std; int main() { int timer; cout << "Set the timer: "; cin >> timer; while(timer > 0) { cout << "Time Remaining:" << timer <<endl; Sleep(1000); --timer; } cout << "\nTime Up!"; return 0; } |
Output:
Set the timer: 4
Time Remaining: 4
Time Remaining: 3
Time Remaining: 2
Time Remaining: 1
Time Up!