Last active
December 16, 2017 16:28
-
-
Save gkiryaziev/aea98522716e1b1eb700b2c16d652969 to your computer and use it in GitHub Desktop.
Countdown timer
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#include <iostream> | |
#include <windows.h> | |
void countdown(int t) { | |
int mins = 0, secs = 0, hours = 0; | |
printf("\n"); | |
while (t) { | |
mins = t / 60; | |
secs = t % 60; | |
if (mins >= 60) { | |
hours = mins / 60; | |
mins = mins % 60; | |
} else { | |
hours = 0; | |
} | |
printf("%02d:%02d:%02d\r", hours, mins, secs); | |
Sleep(1000); | |
t--; | |
} | |
} | |
int main(int argc, char const **argv) | |
{ | |
char *endptr; | |
long int t = strtol(argv[1], &endptr, 10); | |
if ((argc != 2) || (!*argv[1] || *endptr)) { | |
printf("\n\tUsage: countdown.exe [sec.]\n"); | |
return 0; | |
} | |
countdown(atoi(argv[1])); | |
printf("Time's up!\n"); | |
for (int i =0; i < 3; ++i) { | |
Beep(1500, 500); | |
Sleep(500); | |
} | |
return 0; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment