Intro to C++
Project 1
By Coding-Bootcamps.com
########################################
########################################
########################################
Project # 1: Age
//Program to calculate the age of human by entering date of birth
#include <iostream>
using namespace std;

int main()
{
	// Declare variables to hold our data
	int currentDay, currentMonth, currentYear, birthDay, birthMonth, birthYear;
	int d, m, y;
	int currentDay2, currentMonth2, currentYear2;
	// Request info from user
	cout << "Enter the current day = ";
	cin >> currentDay;
	cout << "Enter the current month = ";
	cin >> currentMonth;
	cout << "Enter the current year = ";
	cin >> currentYear;
	cout << "Enter the birth day = ";
	cin >> birthDay;
	cout << "Enter the birth month = ";
	cin >> birthMonth;
	cout << "Enter the birth year = ";
	cin >> birthYear;
	/*  Condition:
			If birth day is before/equal to the current day 
			AND 
			birth month is before/equal to current month OR birth year is before/equal to current year
		Action:
			Simply subtract birth date components from current date.
	*/
	if (birthDay <= currentDay && birthMonth <= currentMonth || birthYear <= currentYear)
	{
		d = currentDay-birthDay;
		m = currentMonth-birthMonth;
		y = currentYear-birthYear;
	}

	/*  Condition:
			If birth day is before/equal to the current day
			AND
			birth month is after current month 
			AND
			birth year is before current year
		Action:
			Subtract birth day from current day. 
			Subtract birth month from current month + 12 (because we cannot subtract December from November)
			Subtract birth year from current year -1 (to make up for the extra 12 months mentioned)
	*/
	if (birthDay <= currentDay && birthMonth > currentMonth && birthYear < currentYear)
	{
		d = currentDay-birthDay;
		currentMonth2 = currentMonth + 12;
		m = currentMonth2-birthMonth;
		y = currentYear-birthYear-1;
	}

	/*  Condition:
			If birth day is after the current day
			AND
			birth month is before current month
			AND
			birth year is before current year
		Action:
			See follow up if statements.
	*/
	if (birthDay > currentDay && birthMonth < currentMonth && birthYear < currentYear)
	{
		/* Action: If current month has 31 days, 
		add 31 days to current day and subtract birth day. 
		When subtracting birth month from current month subtract an additional one to make up for this.
		*/
		if (currentMonth == 1 || currentMonth == 3 || currentMonth == 5 || currentMonth == 7 || currentMonth == 8 || currentMonth == 10 || currentMonth == 12)
		{
			currentDay2 = currentDay + 31;
			d = currentDay2-birthDay;
			m = currentMonth-birthMonth-1;
			y = currentYear-birthYear;
		}

		// Same as above, but with 29 days.
		if (currentMonth == 2 && currentYear % 4 == 0)
		{
			currentDay2 = currentDay + 29;
			d = currentDay2-birthDay;
			m = currentMonth-birthMonth-1;
			y = currentYear-birthYear;
		}

		// Same as above, but with 28 days.
		if (currentMonth == 2 && currentYear % 4 != 0)
		{
			currentDay2 = currentDay + 28;
			d = currentDay2-birthDay;
			m = currentMonth-birthMonth-1;
			y = currentYear-birthYear;
		}

		// Same as above, but with 30 days.
		if (currentMonth == 4 || currentMonth == 6 || currentMonth == 9 || currentMonth == 11)
		{
			currentDay2 = currentDay + 30;
			d = currentDay2-birthDay;
			m = currentMonth-birthMonth-1;
			y = currentYear-birthYear;
		}
	}

	/*  Condition:
		If birth day is after the current day
		AND
		birth month is after/equal current month
		AND
		birth year is before current year
	Action:
		See follow up if statements.
	*/
	if (birthDay > currentDay && birthMonth >= currentMonth && birthYear < currentYear)
	{
		/* ACTION If current month has 31 days,
		add 31 days to current month and subtract birth day.
		When subtracting birth month from current month subtract an additional one to make up for this.

		Also add 12 months to current month in order to subtract birth month (because you couldn't subtract,
		say, December from November. This is then adjusted when doing the year calculation as an additional 1 year is
		deducted.
		*/
		if (currentMonth == 1 || currentMonth == 3 || currentMonth == 5 || currentMonth == 7 || currentMonth == 8 || currentMonth == 10 || currentMonth == 12)
		{
			currentDay2 = currentDay + 31;
			d = currentDay2-birthDay;
			currentMonth2 = currentMonth + 12-1;
			m = currentMonth2-birthMonth;
			y = currentYear-birthYear-1;
		}
		// Same as above but with 29 days
		if (currentMonth == 2 && currentYear % 4 == 0)
		{
			currentDay2 = currentDay + 29;
			d = currentDay2-birthDay;
			currentMonth2 = currentMonth + 12-1;
			m = currentMonth2-birthMonth;
			y = currentYear-birthYear-1;
		}
		// Same as above but with 28 days
		if (currentMonth == 2 && currentYear % 4 != 0)
		{
			currentDay2 = currentDay + 28;
			d = currentDay2-birthDay;
			currentMonth2 = currentMonth + 12-1;
			m = currentMonth2-birthMonth;
			y = currentYear-birthYear-1;
		}
		// Same as above but with 30 days
		if (currentMonth == 4 || currentMonth == 6 || currentMonth == 9 || currentMonth == 11)
		{
			currentDay2 = currentDay + 30;
			d = currentDay2-birthDay;
			currentMonth2 = currentMonth + 12-1;
			m = currentMonth2-birthMonth;
			y = currentYear-birthYear-1;
		}
	}
	// Print out the results
	cout << "The days are = " << d << endl;
	cout << "The months are = " << m << endl;
	cout << "The years are = " << y << endl;
	return 0;
}


########################################


