MeehoweCK

Untitled

Oct 15th, 2020
2,040
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.80 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. using namespace std;
  4.  
  5. int main()
  6. {
  7.     int day, month, year;
  8.  
  9.     cout << "Please enter your birth date (day, month, year): ";
  10.     cin >> day >> month >> year;
  11.  
  12.     int day_today = 15, month_today = 10, year_today = 2020;
  13.  
  14.     bool birthday_this_year = false;
  15.  
  16.     // first we have to find out if the user already had a birthday this year:
  17.     if(month < month_today)
  18.         birthday_this_year = true;
  19.     else if(month == month_today)
  20.         if(day <= day_today)
  21.             birthday_this_year = true;
  22.  
  23.     int age = year_today - year;
  24.  
  25.     if(birthday_this_year)
  26.         cout << "You are " << age << " years old.\n";
  27.     else
  28.     {
  29.         --age;      // decrease the value of age by 1
  30.         cout << "You are " << age << " years old.\n";
  31.     }
  32.     return 0;
  33. }
Advertisement
Add Comment
Please, Sign In to add comment