-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathage-days.cpp
More file actions
111 lines (103 loc) · 2.41 KB
/
age-days.cpp
File metadata and controls
111 lines (103 loc) · 2.41 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
#include <iostream>
#include<conio.h>
using namespace std;
bool leapyr(int n){
if(n%4==0){
if(n%100==0){
if(n%400==0){
return true;
}
else{
return false;
}
}
else{
return true;
}
}
else
{
return false;
}
}
int leapyr_count(int yob,int py,int mob,int pm,int pd){
int noly=0;
if( mob <= 2){
for(int i=yob;i<py;i++){
bool check=leapyr(i);
if(check){
noly++;
}
}
}
else {
for(int i=yob+1;i<py;i++){
bool check=leapyr(i);
if(check){
noly++;
}
}
}
/*if(pm==2 && pd==29){
bool check=leapyr(py);
if(check){
noly++;
}
}*/
if(pm >2){
bool check=leapyr(py);
if(check){
noly++;
}
}
return noly;
}
int main() {
//entering year of birth
cout<<"INSTRUCTIONS \n The date format should be like yyyy/mm/dd \n Press ENTER KEY after each entry"<<endl;
cout<<"for example : \n \t Enter year of -----. \n \t 2008 \n \t 3 \n \t 27 "<<endl;
int yob;
cout<<"Enter year of Birth."<<endl;
cin>>yob;
int mob;
cin>>mob;
int dob;
cin>>dob;
//entering present year
int py;
cout<<"Enter Present year."<<endl;
cin>>py;
int pm;
cin>>pm;
int pd;
cin>>pd;
//count of leap years
int noly=0;
noly=leapyr_count(yob,py,mob,pm,pd);
// cout<<"demo\n"<<noly<<"\ndemo";
// calculating days leaving boundary years
int days=0;
for(int i=yob+1;i<py;i++){
days = days + 365;
}
//cout<<"demo\n"<<days<<"\ndemo";
// adding pending days of leap years
days = days + noly;
// cout<<"demo\n"<<days<<"\ndemo";
// cout<<"demo \n"<<days<<"\ndemo";
// making array of month days
int month[13]={0,31,59,90,120,151,181,212,243,273,304,334,365};
//calculating days
{
days = days + month[12] - month[mob];
//calculating days spend in the month of birth
days = days + month[mob]-month[mob-1]-dob +1;
days = days + month[pm-1];
days = days + pd;
}
if(yob==py){
days=days-365 -2;
}
cout<<endl<<"Age in the days is "<<days<<endl;
return 0;
}