+ 1

How to calculate age from year of birth?

The actual year should not be static

24th Aug 2016, 4:45 PM
Lavnish
Lavnish - avatar
2 Antworten
+ 2
Consider this: (year of birth for example = 1957) #include <iostream> #include <ctime> using namespace std; int date_of_birth = 1957; // for example int main( ) { time_t now = time(0); // number of seconds since January 1, 1970 tm *ltm = localtime(&now); // tm class with tm_year attribute cout « (1900 + ltm->tm_year - date_of_birth); // tm_year is since 1900 } Output: 59 PD: it takes information from OS
24th Aug 2016, 5:08 PM
Néstor
Néstor - avatar
+ 1
current year - birth year should do it? That is, if you're not counting months and days.
24th Aug 2016, 5:07 PM
Cohen Creber
Cohen Creber - avatar