Skip to content

Instantly share code, notes, and snippets.

@gkiryaziev
Last active December 16, 2017 16:28
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save gkiryaziev/aea98522716e1b1eb700b2c16d652969 to your computer and use it in GitHub Desktop.
Save gkiryaziev/aea98522716e1b1eb700b2c16d652969 to your computer and use it in GitHub Desktop.
Countdown timer
#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