Skip to content

Instantly share code, notes, and snippets.

Created Aug 12, 2021
What would you like to do?
#include <iostream>
#include <ctime>
using namespace std;
int main(){
int day, month, year;
struct tm date = {0};
cout<<"Enter Your Date of Birth ( Year Month Day): ";
date.tm_year = year-1900;
date.tm_mon = month-1;
date.tm_mday = day;
time_t normal = mktime(&date);
time_t current;
int age = (difftime(current, normal) + 86400L/2) / 86400L;
cout<<"You are "<<age/365<<" years old.";
return 0;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment