-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathwaktutugas.cpp
118 lines (100 loc) · 1.94 KB
/
waktutugas.cpp
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
#include<iostream>
#include<stdlib.h>
using namespace std;
/*
judul: durasi 1
author: BAgas Rayhan S
A11.202214715
*/
//kamus
int jAkhir, mAkhir, dAkhir;
int jAwal, mAwal, dAwal;
int durasi;
void input(){
cout<<" masukkan waktu mula2"<<endl;
cout<<" Jam: ";cin>>jAwal;
cout<<" menit: ";cin>>mAwal;
cout<<" detik: ";cin>>dAwal;
//--------
cout<<" masukkan waktu saat ini"<<endl;
cout<<" Jam: ";cin>>jAkhir;
cout<<" menit: ";cin>>mAkhir;
cout<<" detik: ";cin>>dAkhir;
}
bool val(int Jo, int Jt, int Mo, int Mt, int Do, int Dt){
if(((Jo>= 0)&&(Jo<24))&&((Jt>= 0)&&(Jt<24))){
if(((Mo>= 0)&&(Mo<24))&&((Mt>= 0)&&(Mt<24))){
if(((Do>= 0)&&(Do<24))&&((Dt>= 0)&&(Dt<24))){
return true;
}
}
}
else{
return false;
}
}
//ampmawal
string AMPMo(int Jo){
//11.59
//23.59
// 0 - 11 -> 12 - 23
if((Jo>= 0)&&(Jo < 12)){
return "AM";
}
else {
return "PM";
}
}
//ampmakhir
string AMPMt(int Jt){
//11.59
//23.59
// 0 - 11 -> 12 - 23
if((Jt>= 0)&&(Jt < 12)){
return "AM";
}
else {
return "PM";
}
}
int jam(int Ho, int Ht){
int jj;
jj = (Ht*3600)-(Ho*3600);
return jj;
}
int menit(int Mo, int Mt){
int MM;
MM = (Mt*60)-(Mo*60);
return MM;
}
int Detik(int Do, int Dt){
int D;
D = Dt - Do;
return D;
}
int dura(){
if(val(jAwal, jAkhir, mAwal, mAkhir, dAwal, dAkhir)){
return Detik(dAwal, dAkhir) + menit(mAwal, mAkhir) + jam(jAwal, jAkhir);
}
else{
cout<<"inputan tidak valid"<<endl;
}
}
// tadi
void tadi(){
cout<<"tadi adalah jam : "<<jAwal<<":"<<mAwal<<AMPMo(jAwal)<<endl;
}
void sekarang(){
cout<<"sekarang adalah jam : "<<jAkhir<<":"<<mAkhir<<AMPMt(jAkhir)<<endl;
}
int main(){
input();
//clear screen
system("cls");
cout<<" =========== "<<endl;
tadi();
cout<<endl;
sekarang();
cout<<" ================ "<<endl;
cout<<"rentang waktu : "<<dura()<<" detik";
}