-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtimer.cpp
More file actions
32 lines (24 loc) · 766 Bytes
/
Copy pathtimer.cpp
File metadata and controls
32 lines (24 loc) · 766 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
#include <iostream>
#include <chrono> // Used to specify time intervals.
#include <thread> // Used to pause the program during the countdown.
#include <ctime> // Used to get and display the current date and time.
int main()
{
int seconds;
// Get the current time.
time_t tt;
time(&tt);
std::cout << "Enter the countdown time (in seconds): ";
std::cin >> seconds;
// LOOP
for (int i = seconds; i >= 1; i--)
{
std::cout << "Time Remaining: " << i << " : " << ctime(&tt);
// Pause the program for 1 second.
std::this_thread::sleep_for(std::chrono::seconds(1));
// Update the current time for the next iteration.
time(&tt);
}
std::cout << "Time's Up!\n";
return 0;
}