-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTimeInc.c
58 lines (56 loc) · 1.01 KB
/
TimeInc.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
/**
* Incrementation program using time
**/
#include <stdio.h>
#include <string.h>
int main(void)
{
// Welcome user to program
printf("Welcome to time incrementation.\nPress any key to incrment the time by one minute.\n");
//create time numbers
int h = 12, m = 00;
char* noon = "AM";
//print first time
printf("%i:0%i %s\n", h, m, noon);
char* n;
while(1)
{
//wait for user to progress program
getch();
m = m + 1;
// progress hours
if(m >= 60)
{
h = h + 1;
m = 00;
}
// reset hours
if(h >= 13)
{
h = 1;
}
//change AM/PM
if (h >= 12 && m <= 00)
{
if(strcmp(noon, "AM") == 0)
noon = "PM";
else if(strcmp(noon, "PM") == 0)
noon = "AM";
else
return 1;
}
// print time
if(m < 10)
{
if(h >= 10)
printf("%i:0%i %s", h, m, noon);
if(h < 10)
printf(" %i:0%i %s", h, m, noon);
}
else if(h < 10)
printf(" %i:%i %s", h, m, noon);
else
printf("%i:%i %s", h, m, noon);
printf("\n");
}
}