fork download
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int calculateAge(int birthYear, int birthMonth, int birthDay, int currentYear, int currentMonth, int currentDay)
  6. {
  7.  
  8. int age;
  9.  
  10. age= currentYear - birthYear;
  11.  
  12. if(currentMonth < birthMonth || (currentMonth == birthMonth && currentDay < birthDay))
  13. {
  14. age--;
  15. }
  16. return age;
  17. }
  18. int main(){
  19.  
  20. int birthYear, birthMonth, birthDay;
  21. int currentYear, currentMonth, currentDay;
  22.  
  23. cout<<"Enter Your Birth Year: " << endl;
  24. cin>>birthYear;
  25. cout<<"Enter Your Birth Month: " << endl;
  26. cin>>birthMonth;
  27. cout<<"Enter Your Birth Day: " << endl;
  28. cin>>birthDay;
  29.  
  30. cout<<"Enter Current Year: " << endl;
  31. cin>>currentYear;
  32. cout<<"Enter Current Month: " << endl;
  33. cin>>currentMonth;
  34. cout<<"Enter Current Day: " << endl;
  35. cin>>currentDay;
  36.  
  37. int age = calculateAge(birthYear, birthMonth, birthDay, currentYear, currentMonth, currentDay);
  38. cout<<"You are now"<< age <<"year/s old";
  39.  
  40. return 0;
  41. }
Success #stdin #stdout 0.01s 5284KB
stdin
Standard input is empty
stdout
Enter Your Birth Year: 
Enter Your Birth Month: 
Enter Your Birth Day: 
Enter Current Year: 
Enter Current Month: 
Enter Current Day: 
You are now1867989469year/s old