-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathTIME AHEAD.c
64 lines (60 loc) · 1.61 KB
/
TIME AHEAD.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
/*program to show time ahead*/
/*note no AM OR PM available in this code
until Updated
input your current time first...
1 for AM 2 for PM...
Then finally the time ahead you want.
in seperate lines*/
#include <stdio.h>
int main() {
//declare required variables
int time,ahead,ntime,newer;
//ask for current time
printf("what is the current time\n");
scanf("%d",&time);
if(time<1 && time>12)
{
printf("error!!! invalid time\nplease try again__");
}
//use 1 to rep am and 2 to rep pm
printf("AM(1) OR PM(2)\n");
scanf("%d",&ahead);
printf("%d",ahead);
switch(ahead)
{
case 1://for AM
printf("\ntime ahead-");
scanf("%d",&newer);
printf(" %d hrs ahead",newer);
ntime = time+newer;
if(ntime>12)
{
ntime-=12;
printf("\n%d ",ntime);
}
else
{
printf("\n%d ",ntime);
}
break;
case 2://for PM
time+=12;
printf("time ahead-");
scanf("%d", &newer);
printf(" %d hrs ahead",newer);
ntime = time + newer;
ntime -= 12;
//always check if the newtime is greater than 12 ad reduce it
do{
if(ntime >12)
{
ntime-= 12;
}
}while(ntime>12);
printf("\n%d",ntime);
break;
default:
printf("wrong choice");
}
return 0;
}