-
Notifications
You must be signed in to change notification settings - Fork 0
/
h2.cpp
executable file
·41 lines (31 loc) · 900 Bytes
/
h2.cpp
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
33
34
35
36
37
38
39
40
41
/*
* Challenge H2
* https://www.reddit.com/r/dailyprogrammer/comments/pjsdx/difficult_challenge_2/
*/
#include <iostream>
int main() {
std::cout << "Stopwatch" << std::endl;
std::cout << "l = lap; q = quit" << std::endl;
std::cout << "Enter 's' to start" << std::endl;
std::time_t start;
char choice;
std::cin >> choice;
if (choice == 's'){
start = std::time(NULL);
}
else {
std::cout << "Invalid choice. Exiting." << std::endl;
return 0;
}
std::time_t last = start;
while (choice != 'q'){
std::cin >> choice;
if (choice == 'l') {
std::cout << std::time(NULL) - last << " seconds" << std::endl;
last = std::time(NULL);
}
}
std::cout << "Ran for " << std::time(NULL) - start << " seconds" << std::endl;
std::cout << "Goodbye." << std::endl;
return 0;
}