-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathMain.cpp
More file actions
233 lines (202 loc) · 5.25 KB
/
Main.cpp
File metadata and controls
233 lines (202 loc) · 5.25 KB
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
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
// cpp prog to convert time to hrs or time into world time
#include<iostream>
using namespace std;
int minstohours(int x);
int loctoglobe(string zone, int y, int z);
int gmtconvert(int y, int z);
int istconvert(int y, int z);
int edtconvert(int y, int z);
int cstconvert(int y, int z);
int main() {
int options;
cout << "enter 0 to convert minutes into hours and 1 for converting local time to world time" << endl;
cin >> options;
switch (options) {
case 0:
cout << "enter time in minutes" << endl;
int minutes;
cin >> minutes;
minstohours(minutes);
break;
case 1:
cout << "enter time zone" << endl;
string timezone;
cin >> timezone;
cout << "enter time as hours" << endl;
int hours;
cin >> hours;
cout << "enter time as mins" << endl;
int mins;
cin >> mins;
loctoglobe(timezone, hours, mins);
break;
}
}
int minstohours(int x) {
int minsafterconversion;
int hrsafterconversion;
minsafterconversion = x % 60;
hrsafterconversion = x / 60;
if (hrsafterconversion > 24) {
int daysafterconversion;
daysafterconversion = hrsafterconversion / 24;
hrsafterconversion = hrsafterconversion % 24;
cout << "the time converted into days and hours is: " << endl;
cout << "DAYS: " << daysafterconversion << " HOURS: " << hrsafterconversion << " MINS: " << minsafterconversion << endl;
}
else {
cout << "the time converted into hours is: " << endl;
cout << "HOURS: " << hrsafterconversion << " MINS: " << minsafterconversion << endl;
}
return 0;
}
int loctoglobe(string zone, int y, int z) {
//timezones used are gmt, ist, edt, cst
if (zone == "gmt" || zone == "GMT") {
gmtconvert(y, z);
}
else if (zone == "ist" || zone == "IST") {
istconvert(y, z);
}
else if (zone == "edt" || zone == "EDT") {
edtconvert(y, z);
}
else if (zone == "cst" || zone == "CST") {
cstconvert(y, z);
}
else {
cout << "invalid input" << endl;
}
return 0;
}
int gmtconvert(int y, int z) {
int isthrs, istmins, edthrs, edtmins, csthrs, cstmins;
isthrs = y + 5;
istmins = z + 30;
if (istmins > 60) {
isthrs++;
istmins = istmins - 60;
}
if (isthrs >= 24) {
isthrs = isthrs - 24;
}
cout << "Time(ist): " << isthrs << ":" << istmins << endl;
//gmt to edt
edthrs = y - 8;
edtmins = z;
if (edtmins > 60) {
edthrs++;
edtmins = edtmins - 60;
}
if (edthrs <= 0) {
edthrs = edthrs + 24;
}
cout << "Time(edt): " << edthrs << ":" << edtmins << endl;
//gmt to cst
csthrs = y - 5;
cstmins = z;
if (cstmins > 60) {
csthrs++;
cstmins = cstmins - 60;
}
if (csthrs <= 0) {
csthrs = csthrs + 24;
}
cout << "Time(cst): " << csthrs << ":" << cstmins << endl;
return 0;
}
int istconvert(int y, int z) {
int gmthrs, gmtmins, edthrs, edtmins, csthrs, cstmins;
//ist to gmt
gmthrs = y - 5;
gmtmins = z - 30;
if (gmtmins < 0) {
gmtmins = gmtmins + 60;
gmthrs--;
}
if (gmthrs < 0) {
gmthrs = gmthrs + 24;
}
cout << "Time(gmt): " << gmthrs << ":" << gmtmins << endl;
//ist to edt
edthrs = y - 9;
edtmins = z - 30;
if (edtmins < 0) {
edtmins = edtmins + 60;
edthrs--;
}
if (edthrs < 0) {
edthrs = edthrs + 24;
}
cout << "Time(edt): " << edthrs << ":" << edtmins << endl;
//ist to cst
csthrs = y - 10;
cstmins = z - 30;
if (cstmins < 0) {
cstmins = cstmins + 60;
csthrs--;
}
if (csthrs < 0) {
csthrs = csthrs + 24;
}
cout << "Time(cst): " << csthrs << ":" << cstmins << endl;
return 0;
}
int edtconvert(int y, int z) {
int isthrs, istmins, gmthrs, gmtmins, csthrs, cstmins;
//edt to gmt
gmthrs = y + 4;
gmtmins = z;
if (gmthrs >= 24) {
gmthrs = gmthrs - 24;
}
cout << "Time(gmt): " << gmthrs << ":" << gmtmins << endl;
//edt to ist
isthrs = y + 9;
istmins = z + 30;
if (istmins >= 60) {
istmins = istmins - 60;
isthrs++;
}
if (isthrs >= 24) {
isthrs = isthrs - 24;
}
cout << "Time(ist): " << isthrs << ":" << istmins << endl;
//edt to cst
csthrs = y - 1;
cstmins = z;
if (csthrs < 0) {
csthrs = csthrs + 24;
}
cout << "Time(cst): " << csthrs << ":" << cstmins << endl;
return 0;
}
int cstconvert(int y, int z) {
int isthrs, istmins, gmthrs, gmtmins, edthrs, edtmins;
//cst to gmt
gmthrs = y + 5;
gmtmins = z;
if (gmthrs >= 24) {
gmthrs = gmthrs - 24;
}
cout << "Time(gmt): " << gmthrs << ":" << gmtmins << endl;
//cst to ist
isthrs = y + 10;
istmins = z + 30;
if (istmins >= 60) {
istmins = istmins - 60;
isthrs++;
}
if (isthrs >= 24) {
isthrs = isthrs - 24;
}
cout << "Time(ist): " << isthrs << ":" << istmins << endl;
//cst to edt
edthrs = y + 1;
edtmins = z;
if (edthrs > 24) {
edthrs = edthrs - 24;
}
cout << "Time(edt): " << edthrs << ":" << edtmins << endl;
return 0;
}