2. Don't ask the user to enter a string, use an int (1-12). Less to type, easier to compare. If the user types even one letter incorrectly for the month, it won't match.
3. To expand on salem c's recommendation, <ctime> includes a tm structure, holding a calendar date and time broken down into its components. This makes calculating a time duration like a user's current age MUCH easier. https://en.cppreference.com/w/c/chrono/tm
4. Calculating the user's current age: subtract birth_year from current_year, subtracting one year from that total if the current_month is less than the birth_month. int age = current_year - birth_year - ((current_month < birth_month) ? 1 : 0);
It is the ternary operator AKA the conditional operator, and no better time to begin learning than now. It is very efficient when used properly.
<test condition> ? <true result> : <false result> is a compact way to do an if/else block.
What was done in one statement would require multiple statements:
1. the original age definition int age = current_year - birth_year;
2. with an ugly if/else block to check if the current_month is less than the birth_month.
1 2 3 4 5 6 7 8 9 10
int age = current_year - birth year;
if (current_month < birth_month)
{
age -= 1;
}
else
{
are -= 0;
}
Since the condition when the current month equals or is greater than the birth month doesn't actually change the age variable you could skip else clause block.