-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdevtimer.cpp
More file actions
31 lines (25 loc) · 793 Bytes
/
Copy pathdevtimer.cpp
File metadata and controls
31 lines (25 loc) · 793 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
#include <iostream>
#include <chrono>
#include <thread>
int main(int argc, char* argv[]) {
if(argc < 4){
std::cout << "Usage: devtimer start <time> <unit: sec|min>\n";
return 1;
}
std::string command = argv[1];
int time = std::stoi(argv[2]);
std::string unit = argv[3];
if(command == "start") {
std::cout << "Timer started for " << time << " " << unit << "...\n";
if(unit == "min") {
std::this_thread::sleep_for(std::chrono::minutes(time));
} else if(unit == "sec") {
std::this_thread::sleep_for(std::chrono::seconds(time));
} else {
std::cout << "Invalid unit. Use 'sec' or 'min'.\n";
return 1;
}
std::cout << "\aTime's up!\n";
}
return 0;
}