+ 1
How to calculate age from year of birth?
The actual year should not be static
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
+ 1
current year - birth year
should do it? That is, if you're not counting months and days.