Advertisement
avr39ripe

BR012daysInMonth

Jan 20th, 2021
109
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 0.73 KB | None | 0 0
  1. #include <iostream>
  2.  
  3. //month#    1   2   3   4   5   6   7           #   8   9   10  11  12
  4. //days      31  28  31  30  31  30  31          #   31  30  31  30  31
  5. //          (month < 8) and (month % 2 != 0)    # (month >= 8) and (month % 2 == 0)
  6. //          ((month < 8) and (month % 2 != 0)) or ((month >= 8) and (month % 2 == 0))
  7. int main()
  8. {
  9.     int days{ 30 };
  10.     int month{ 2 };
  11.     int year{ 2021 };
  12.  
  13.     std::cout << "Enter year:\n";
  14.     std::cin >> year;
  15.     std::cout << "Enter month 1-12:\n";
  16.     std::cin >> month;
  17.  
  18.     const bool isLeap{ (year % 400 == 0) or (year % 4 == 0) and (year % 100 != 0) };
  19.    
  20.     days += ((month < 8) and (month % 2 != 0) or (month >= 8) and (month % 2 == 0)) + (-2 * (month == 2) + isLeap);
  21.  
  22.     std::cout << "In month# " << month << " there are " << days << " days\n";
  23.     return 0;
  24. }
  25.  
  26.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement