#include <iostream> #include <string> using namespace std; int main() { int yearnow; int monthnow; int yearborn; int monthborn; int daynow; int dayborn; cout << "Enter the current year: "; cin >> yearnow; cout << "Enter the current month: "; cin >> monthnow; cout << "Enter the current day: "; cin >> daynow; cout << "Enter the year when you were born: "; cin >> yearborn; cout << "Enter the month when you were born: "; cin >> monthborn; cout << "Enter the day when you were born: "; cin >> dayborn; int yearactual = yearnow - yearborn; if (monthborn > monthnow){ cout << "You are " << yearactual - 1 << " years old\n"; cout << "You are " << 12 - (monthborn - monthnow) - 1 << " months old\n"; cout << "And " << daynow << " days old"; } if (monthborn < monthnow){ if (daynow > dayborn){ cout << "You are " << yearactual << " years old\n"; cout << "You are " << monthnow - monthborn << " months old\n"; cout << "And " << daynow - dayborn << " days old"; } if (daynow < dayborn){ cout << "You are " << yearactual << " years old\n"; cout << "You are " << monthnow - monthborn - 1<< " months old\n"; cout << "And " << daynow << " days old"; } if (daynow == dayborn){ cout << "You are " << yearactual << " years old\n"; cout << "You are " << monthnow - monthborn << " months old\n"; cout << "And " << "0" << " days old"; } } if (monthborn == monthnow){ cout << "You are " << yearactual << " years old\n"; cout << "You are " << "0" << " months old\n"; cout << "And " << daynow << " days old"; } return 0; }
Preview:
downloadDownload PNG
downloadDownload JPEG
downloadDownload SVG
Tip: You can change the style, width & colours of the snippet with the inspect tool before clicking Download!
Click to optimize width for Twitter