Advertisement
avr39ripe

cppDaysInMonth

Feb 24th, 2021
142
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. // 1        2       3       4       5       6       7    #   8       9       10      11      12
  4. // 31       28      31      30      31      30      31   #   31      30      31      30      31
  5. // (month < 8)                                            (month >= 8)
  6. // (month % 2 != 0)                                       (month % 2 == 0)
  7. //((month < 8) and (month % 2 != 0)) or ((month >= 8) and (month % 2 == 0))
  8. int main()
  9. {
  10.     int month{ 5 };
  11.     int daysInMonth{30};
  12.  
  13.     std::cout << "Enter month number from 1 to 12\n";
  14.     std::cin >> month;
  15.  
  16.     daysInMonth += (((month < 8) and (month % 2 != 0)) or ((month >= 8) and (month % 2 == 0))) + ((month == 2)*(-2));
  17.  
  18.     std::cout << "There are " << daysInMonth << " days in " << month << " month\n";
  19.  
  20.     return 0;
  21. }
  22.  
  23.  
  24.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement