All Projects

Bus Ticket Booking System in Python
Bus Ticket Booking System in Java
Bus Ticket Booking System in Cpp
Bus Ticket Booking System in C
Cafe Order System in Python
Cafe Order System in Java
Cafe Order System in Cpp
Cafe Order System in C
Social Media Account Details Manager in Python
Social Media Account Details Manager in Java
Social Media Account Details Manager in Cpp
Social Media Account Details Manager in C
Mini ATM in Python Language
Mini ATM in Java Language
Mini ATM in cpp language
Mini ATM in c language
Pocket Money Manager in Python Language
Pocket Money Manager in Java Language
Pocket Money Manager in Cpp Language
Pocket Money Manager in C Language
Username Password Generator in Python Language
Username Password Generator in Cpp Language
Username Password Generator in C Language
Telephone Directory in Python Language
Telephone Directory in Java Language
Telephone Directory in Cpp Language
Telephone Directory in C Language
Calander in Cpp Language
Calander in C Language
NoteBook in Python Language
NoteBook in Cpp Language
NoteBook in C Language
Voting System in Python Language
Voting System in Java Language
Voting System in Cpp Language
Voting System in C Language
Age Calculator in Python Language
Age Calculator in Java Language
Age Calculator in Cpp Language
Age Calculator in C Language
Currency Converter in Python Language
Currency Converter in Java Language
Currency Converter in Cpp Language
Currency Converter in C Language
Random Password Generator in python language
Random Password Generator in java language
Random Password Generator in cpp language
Random Password Generator in c language
Billing System in python language
Billing System in c++ language
Billing System in c language
Atm in c language

Age Calculator in Cpp Language


Aniket The Programmer

1K+ Subscribers

Click To Subscribe My Channel

Subscribe

Source Code

        
#include
#include
using namespace std;

// make function to calculate age
void AgeCalculate(char g, int current_date, int current_month, int current_year, int birth_date, int birth_month, int birth_year) {
    int month[] =  { 31, 28, 31, 30, 31, 30,
                    31, 31, 30, 31, 30, 31 }; // days in month

    if (birth_date > current_date) {
        current_date = current_date + month[birth_month - 1];
        current_month = current_month - 1;
    } 
    if (birth_month > current_month) {
        current_year = current_year - 1;
        current_month = current_month + 12;
    }  
    int calculated_date = current_date - birth_date;
    int calculated_month = current_month - birth_month;
    int calculated_year = current_year - birth_year;

    cout << "Your Age   Year : " << calculated_year << " Month : " << calculated_month << " Day : " << calculated_date << endl;
    
    // for fun
    if (g == 'm' && (18 < calculated_year && calculated_year < 28)) {
        cout << "You are se*y boy :)";
    }
    if (g == 'f' && (18 < calculated_year && calculated_year < 28)) {
        cout << "You are se*y girl :)";
    }
}

int main() {
    cout << "Welcome to age calculator";
    time_t t = time(NULL);
    struct tm tm = *localtime(&t);
    // finding current date with month and year
    int current_date = tm.tm_mday;
    int current_month = tm.tm_mon + 1; // start from 0
    int current_year = tm.tm_year + 1900;

    int birth_date, birth_month, birth_year;
    char g; // for gender
    cout << "Enter your gender m for male and f for female";
    cin >> g;
    cout << "Enter your birth date";
    cin >> birth_date;
    cout << "Enter your birth month";
    cin >> birth_month;
    cout << "Enter your birth year";
    cin >> birth_year;

    // calling function
    AgeCalculate(g, current_date, current_month, current_year, birth_date, birth_month, birth_year);
    cout << "";
}
        
    

Source Code Github Link: View

View Video On Youtube Link: View