Advertisement
Guest User

Untitled

a guest
Sep 19th, 2019
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.09 KB | None | 0 0
  1. #include <iostream>
  2. #include <iomanip>
  3.  
  4. using namespace std;
  5.  
  6. int main()
  7. {
  8. int month, date, year, u, v, w, m, y, day;
  9. string weekday;
  10.  
  11.  
  12. cout << "Enter numeric values for date, month, and year -> ";
  13. cin >> month >> date >> year;
  14. bool validDate, leap = year % 400 == 0 || (year % 4 == 0 && year % 100 != 0);
  15. if (month < 1 || month > 12 || date < 1 || date > 31 || year < 1583 || month > 12 || month < 0)
  16. validDate = false;
  17. else if (date == 31 && (month == 4 || month == 6 || month == 9 || month == 11))
  18. validDate = false;
  19. else if (month == 2)
  20. {
  21. if (leap)
  22. {
  23. if (date > 29)
  24. validDate = false;
  25. else
  26. validDate = true;
  27. }
  28. else if (date > 28)
  29. validDate = false;
  30. else
  31. validDate = true;
  32. }
  33. else
  34. validDate = true;
  35. {
  36. if (month == 1)
  37. {
  38. if (leap == true)
  39. m = 6;
  40. else
  41. m = 0;
  42. }
  43. else if (month == 2)
  44. {
  45. if (leap == true)
  46. m = 2;
  47. else
  48. m = 3;
  49. }
  50. else if (month == 3 || 11)
  51. m = 3;
  52. else if (month == 4 || 7)
  53. m = 6;
  54. else if (month == 5)
  55. m = 1;
  56. else if (month == 6)
  57. m = 4;
  58. else if (month == 8)
  59. m = 2;
  60. else if (month == 9 || 12)
  61. m = 5;
  62. else
  63. m = 0;
  64. }
  65. u = year / 100;
  66. v = year % 100;
  67. w = v / 4;
  68. y = u + v + w + m + date;
  69. day = y % 7;
  70.  
  71. {
  72. if (day == 0)
  73. weekday = "Sunday";
  74. else if (day == 1)
  75. weekday = "Monday";
  76. else if (day == 2)
  77. weekday = "Tuesday";
  78. else if (day == 3)
  79. weekday = "Wednesday";
  80. else if (day == 4)
  81. weekday = "Thursday";
  82. else if (day == 5)
  83. weekday = "Friday";
  84. else
  85. weekday = "Saturday";
  86. }
  87.  
  88.  
  89. if (validDate)
  90. {
  91. if (leap)
  92. cout << weekday << " " << setw(2) << setfill('0') << month << "/" << setw(2) << setfill('0') << date << "/" << year
  93. << " is a valid date and is on a leap year." << endl;
  94. else
  95. cout << weekday << " " << setw(2) << setfill('0') << month << "/" << setw(2) << setfill('0') << date << "/" << year
  96. << " is a valid date and is not on a leap year." << endl;
  97. }
  98. else
  99. cout << month << "/" << date << "/" << year << " is not a valid date." << endl;
  100. return 0;
  101. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement