Advertisement
Guest User

Untitled

a guest
Nov 1st, 2014
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.53 KB | None | 0 0
  1. #include <iostream>
  2. using namespace std;
  3.  
  4. bool is_leap_year(const int year);
  5. int days_in_month(const bool is_leap_year, const int month);
  6. void print_calender(int month);
  7.  
  8. int main()
  9. {
  10. int year = 0;
  11. int day = 0;
  12. bool day_valid = false;
  13.  
  14. while (!year)
  15. {
  16. cout << "Enter the year: ";
  17. cin >> year;
  18. if (year < 0 || year > 9999)
  19. {
  20. cout << "That's not a valid year!" << endl;
  21. year = 0;
  22. }
  23. }
  24.  
  25. while (!day_valid)
  26. {
  27. cout << "Enter the day of the week of January 1st, using 0 through 6." << endl;
  28. cout << "(0 = Sun, 1 = Mon, 2 = Tue, 3 = Wed, 4 = Thu, 5 Fri, 6 = Sat)" << endl;
  29. cin >> day;
  30.  
  31. if (day < 0 || day > 6)
  32. {
  33. cout << "That's not a valid day! Must be between 0 and 6!" << endl;
  34. }
  35. else
  36. {
  37. day_valid = true;
  38. }
  39. }
  40.  
  41. bool leap_year = is_leap_year(year);
  42.  
  43. if (leap_year)
  44. {
  45. cout << year << " is a leap year." << endl;
  46. cout << "There are 29 days in February." << endl;
  47. }
  48. else
  49. {
  50. cout << year << " is not a leap year." << endl;
  51. cout << "There are 28 days in February." << endl;
  52. }
  53.  
  54. int month = 0;
  55. while (!month)
  56. {
  57. cout << "Enter the month: ";
  58. cin >> month;
  59.  
  60. if (month < 0 || month > 11)
  61. {
  62. cout << "That's not a valid month!" << endl;
  63. month = 0;
  64. }
  65. }
  66. cout << "There are " << days_in_month(leap_year, month) << " days in that month!" << endl;
  67. }
  68.  
  69. bool is_leap_year(const int year)
  70. {
  71. if (year % 4 == 0)
  72. {
  73. if (year % 100 == 0 && year % 400 != 0)
  74. return false;
  75. return true;
  76. }
  77. return false;
  78. }
  79.  
  80. int days_in_month(const bool is_leap_year, const int month)
  81. {
  82. int days_count = 0;
  83.  
  84. switch (month)
  85. {
  86. case 8: case 3: case 5: case 10:
  87. days_count = 30;
  88. break;
  89.  
  90. case 1:
  91. if (is_leap_year)
  92. {
  93. days_count = 29;
  94. }
  95. else
  96. {
  97. days_count = 28;
  98. }
  99. break;
  100.  
  101. default:
  102. days_count = 31;
  103. }
  104. return days_count;
  105. }
  106.  
  107. void print_calender(int month)
  108. {
  109. for (int month = 0; month < 12; ++month)
  110. {
  111. switch (month)
  112. {
  113. case 0:
  114. return "January";
  115. case 1:
  116. return "February";
  117. case 2:
  118. return "March";
  119. case 3:
  120. return "April";
  121. case 4:
  122. return "May";
  123. case 5:
  124. return "June";
  125. case 6:
  126. return "July";
  127. case 7:
  128. return "August";
  129. case 8:
  130. return "September";
  131. case 9:
  132. return "October";
  133. case 10:
  134. return "November";
  135. case 11:
  136. return "December";
  137. }
  138. }
  139. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement