-
Notifications
You must be signed in to change notification settings - Fork 0
/
timer.c
91 lines (88 loc) · 1.62 KB
/
timer.c
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
int main()
{
// User Input section.
int h, m, s; // HOUR MINUTE SECOND
printf("Set your timer:\n");
printf("Enter the hours you want your timer to run: ");
scanf("%d", &h);
printf("Enter the minutes you want your timer to run: ");
scanf("%d", &m);
printf("Enter the seconds you want your timer to run: ");
scanf("%d", &s);
// Logic section.
// If the time is set to negetive
if (h < 0 || m < 0 || s < 0)
{
system("cls");
printf("You have set your timer to a negative time.\nINVALID INPUT\nPlease provide a valid time\n");
}
// If the time is set to zero
else if (h == 0 && m == 0 && s == 0)
{
system("cls");
printf("You have set your timer to 0\n");
}
// If everything is alright then the timer will start
else
{
printf("Your counter started from %02d h : %02d m : %02d s\n", h, m, s);
while(s > 0)
{
system("cls");
if (s < 0)
{
//s = 0;
goto min;
}
else
{
printf("Timer: %02d h : %02d m : %02d s", h, m, s);
sleep(1);
system("cls");
}
s--;
}
min:
while(m > 0)
{
system("cls");
if (m < 0)
{
//m = 0;
goto hour;
}
else
{
printf("Timer: %02d h : %02d m : %02d s", h, m, s);
sleep(60);
system("cls");
}
m--;
}
hour:
while(h > 0)
{
system("cls");
if (h < 0)
{
// h = 0;
// m = 0;
// s = 0;
goto end;
}
else
{
printf("Timer: %02d h : %02d m : %02d s", h, m, s);
sleep(360);
system("cls");
}
h--;
}
}
end:
printf("Your counter has ended\nRun the program again to restart the counter.\n");
return 0;
}